mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[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:
@@ -48,6 +48,20 @@ class ContractAbstractContract(models.AbstractModel):
|
|||||||
help="Mark this check if you want to control recurrrence at line level instead"
|
help="Mark this check if you want to control recurrrence at line level instead"
|
||||||
" of all together for the whole contract.",
|
" 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")
|
@api.onchange("contract_type")
|
||||||
def _onchange_contract_type(self):
|
def _onchange_contract_type(self):
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
|
from odoo.osv import expression
|
||||||
from odoo.tests import Form
|
from odoo.tests import Form
|
||||||
from odoo.tools.translate import _
|
from odoo.tools.translate import _
|
||||||
|
|
||||||
@@ -595,10 +596,16 @@ class ContractContract(models.Model):
|
|||||||
return moves
|
return moves
|
||||||
|
|
||||||
@api.model
|
@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:
|
if not date_ref:
|
||||||
date_ref = fields.Date.context_today(self)
|
date_ref = fields.Date.context_today(self)
|
||||||
domain = self._get_contracts_to_invoice_domain(date_ref)
|
domain = self._get_contracts_to_invoice_domain(date_ref)
|
||||||
|
domain = expression.AND(
|
||||||
|
[
|
||||||
|
domain,
|
||||||
|
[("generation_type", "=", create_type)],
|
||||||
|
]
|
||||||
|
)
|
||||||
invoice_obj = self.env["account.move"]
|
invoice_obj = self.env["account.move"]
|
||||||
|
|
||||||
contracts = self.search(domain)
|
contracts = self.search(domain)
|
||||||
@@ -616,6 +623,10 @@ class ContractContract(models.Model):
|
|||||||
)
|
)
|
||||||
return invoice_obj.browse(invoice_ids)
|
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):
|
def action_terminate_contract(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
context = {"default_contract_id": self.id}
|
context = {"default_contract_id": self.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user