From 59e2099eaf7beebd16bf63dda05c9a43d5e3304b Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 10 Aug 2022 18:07:57 +0200 Subject: [PATCH] [IMP] contract: Add contract date In some cases, the contract date (e.g.: signature date) can be different from the start date (e.g.: signature on 05/15/2022 and start date on 06/01/2022). It can have importance in case of prices revisions from a legal point of view as this is the contract date that has to be taken into account. --- contract/__manifest__.py | 2 +- contract/migrations/13.0.2.10.0/pre-migrate.py | 18 ++++++++++++++++++ contract/models/abstract_contract.py | 5 +++++ contract/views/contract.xml | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 contract/migrations/13.0.2.10.0/pre-migrate.py diff --git a/contract/__manifest__.py b/contract/__manifest__.py index 005eecb29..99c61bdf1 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -11,7 +11,7 @@ { "name": "Recurring - Contracts Management", - "version": "13.0.2.9.0", + "version": "13.0.2.10.0", "category": "Contract Management", "license": "AGPL-3", "author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)", diff --git a/contract/migrations/13.0.2.10.0/pre-migrate.py b/contract/migrations/13.0.2.10.0/pre-migrate.py new file mode 100644 index 000000000..ecad5784f --- /dev/null +++ b/contract/migrations/13.0.2.10.0/pre-migrate.py @@ -0,0 +1,18 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + fields_list = [ + ("date", "contract.contract", "contract_contract", "date", "date", "contract") + ] + openupgrade.add_fields(env, fields_list) + query = """ + UPDATE contract_contract + SET date = date_start + WHERE date IS NULL + """ + openupgrade.logged_query(env.cr, query) diff --git a/contract/models/abstract_contract.py b/contract/models/abstract_contract.py index 377f32f14..446ece48c 100644 --- a/contract/models/abstract_contract.py +++ b/contract/models/abstract_contract.py @@ -18,6 +18,11 @@ class ContractAbstractContract(models.AbstractModel): NO_SYNC = ["name", "partner_id", "company_id"] name = fields.Char(required=True) + date = fields.Date( + required=True, + default=lambda self: fields.Date.today(), + help="This is the date the contract is taken into account (e.g.: signature date)", + ) # Needed for avoiding errors on several inherited behaviors partner_id = fields.Many2one( comodel_name="res.partner", string="Partner", index=True diff --git a/contract/views/contract.xml b/contract/views/contract.xml index 710f080c5..e5a421f1b 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -103,6 +103,10 @@ +