diff --git a/contract/models/abstract_contract.py b/contract/models/abstract_contract.py index 377f32f14..cb951f227 100644 --- a/contract/models/abstract_contract.py +++ b/contract/models/abstract_contract.py @@ -48,6 +48,20 @@ class ContractAbstractContract(models.AbstractModel): help="Mark this check if you want to control recurrrence at line level instead" " of all together for the whole contract.", ) + generation_type = fields.Selection( + string="Generation Type", + selection=lambda self: self._get_generation_type_selection(), + default=lambda self: self._get_default_generation_type(), + help="Choose the document that will be automatically generated by cron.", + ) + + @api.model + def _get_generation_type_selection(self): + return [("invoice", "Invoice")] + + @api.model + def _get_default_generation_type(self): + return "invoice" @api.onchange("contract_type") def _onchange_contract_type(self): diff --git a/contract/models/contract.py b/contract/models/contract.py index 61c0fbda5..f41ed0428 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -9,6 +9,7 @@ from odoo import api, fields, models from odoo.exceptions import UserError, ValidationError +from odoo.osv import expression from odoo.tests import Form from odoo.tools.translate import _ @@ -595,10 +596,16 @@ class ContractContract(models.Model): return moves @api.model - def cron_recurring_create_invoice(self, date_ref=None): + def _cron_recurring_create(self, date_ref=False, create_type="invoice"): if not date_ref: date_ref = fields.Date.context_today(self) domain = self._get_contracts_to_invoice_domain(date_ref) + domain = expression.AND( + [ + domain, + [("generation_type", "=", create_type)], + ] + ) invoice_obj = self.env["account.move"] contracts = self.search(domain) @@ -616,6 +623,10 @@ class ContractContract(models.Model): ) return invoice_obj.browse(invoice_ids) + @api.model + def cron_recurring_create_invoice(self, date_ref=None): + return self._cron_recurring_create(date_ref) + def action_terminate_contract(self): self.ensure_one() context = {"default_contract_id": self.id}