From 587fb7c3ff80b6b36d1319af8b3cd1d82056255c Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 3 Dec 2018 18:10:52 +0100 Subject: [PATCH] [FIX] - compute recurring_next_date for contract [IMP] - get contract line default data onchange product_id --- contract/models/abstract_contract_line.py | 21 +++++++++++++++++++++ contract/models/contract.py | 4 ++-- contract/views/contract_line.xml | 3 +-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/contract/models/abstract_contract_line.py b/contract/models/abstract_contract_line.py index 4dc9c8e4..92dc584b 100644 --- a/contract/models/abstract_contract_line.py +++ b/contract/models/abstract_contract_line.py @@ -79,6 +79,7 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel): help="Repeat every (Days/Week/Month/Year)", required=True, ) + date_start = fields.Date(string='Date Start') recurring_next_date = fields.Date(string='Date of Next Invoice') is_canceled = fields.Boolean(string="Canceled", default=False) @@ -204,3 +205,23 @@ class AccountAbstractAnalyticContractLine(models.AbstractModel): vals['price_unit'] = product.price self.update(vals) return {'domain': domain} + + @api.onchange('product_id') + def _onchange_product_id_recurring_info(self): + for rec in self: + rec.date_start = fields.Date.today() + if rec.product_id.is_contract: + rec.recurring_rule_type = rec.product_id.recurring_rule_type + rec.recurring_invoicing_type = ( + rec.product_id.recurring_invoicing_type + ) + rec.recurring_interval = rec.product_id.recurring_interval + rec.is_auto_renew = rec.product_id.is_auto_renew + rec.auto_renew_interval = rec.product_id.auto_renew_interval + rec.auto_renew_rule_type = rec.product_id.auto_renew_rule_type + rec.termination_notice_interval = ( + rec.product_id.termination_notice_interval + ) + rec.termination_notice_rule_type = ( + rec.product_id.termination_notice_rule_type + ) diff --git a/contract/models/contract.py b/contract/models/contract.py index ee144b67..00344e49 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -60,9 +60,9 @@ class AccountAnalyticAccount(models.Model): def _compute_recurring_next_date(self): for contract in self: recurring_next_date = contract.recurring_invoice_line_ids.filtered( - 'create_invoice_visibility' + 'recurring_next_date' ).mapped('recurring_next_date') - if recurring_next_date and all(recurring_next_date): + if recurring_next_date: contract.recurring_next_date = min(recurring_next_date) @api.depends('recurring_invoice_line_ids.create_invoice_visibility') diff --git a/contract/views/contract_line.xml b/contract/views/contract_line.xml index 69ee02b1..e89e352b 100644 --- a/contract/views/contract_line.xml +++ b/contract/views/contract_line.xml @@ -99,8 +99,7 @@ + required="1"/>