[IMP] contract: Add a generation type on contract

Add a generation type on contract that allows to generate other
document than invoice (e.g. sale order)
This commit is contained in:
Denis Roussel
2021-11-04 11:43:35 +01:00
parent 57388a415d
commit f38f94b532
2 changed files with 26 additions and 1 deletions

View File

@@ -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):

View File

@@ -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}