From f1e111b316ba47e107af645a92a67a9cbf95a782 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 4 Jan 2019 14:16:08 +0100 Subject: [PATCH] [FIX] - filter by termination_notice for contract line to renew --- contract/models/contract_line.py | 15 ++++++++++----- contract/tests/test_contract.py | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index 78ca33b1..b2d51428 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -843,12 +843,8 @@ class AccountAnalyticInvoiceLine(models.Model): @api.model def _contract_line_to_renew_domain(self): - date_ref = fields.Date.context_today(self) + self.get_relative_delta( - self.termination_notice_rule_type, self.termination_notice_interval - ) return [ ('is_auto_renew', '=', True), - ('date_end', '<=', date_ref), ('is_canceled', '=', False), ('contract_id.recurring_invoices', '=', True), ] @@ -856,7 +852,16 @@ class AccountAnalyticInvoiceLine(models.Model): @api.model def cron_renew_contract_line(self): domain = self._contract_line_to_renew_domain() - to_renew = self.search(domain) + to_renew = self + for contract_line in self.search(domain): + date_ref = fields.Date.context_today( + self + ) + self.get_relative_delta( + contract_line.termination_notice_rule_type, + contract_line.termination_notice_interval, + ) + if contract_line.date_end <= date_ref: + to_renew |= contract_line to_renew.renew() @api.model diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index 2646567b..5194f99b 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -1256,7 +1256,10 @@ class TestContract(TestContractBase): {'date_end': fields.Date.today() - relativedelta(months=2)} ) self.acct_line.copy( - {'date_end': fields.Date.today() + relativedelta(months=2)} + { + 'date_end': fields.Date.today() + relativedelta(months=2), + 'is_auto_renew': False, + } ) to_renew = self.acct_line.search( self.acct_line._contract_line_to_renew_domain()