Browse Source

[FIX] - filter by termination_notice for contract line to renew

13.0-mig-contract
sbejaoui 6 years ago
committed by Administrator
parent
commit
f1e111b316
  1. 15
      contract/models/contract_line.py
  2. 5
      contract/tests/test_contract.py

15
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

5
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()

Loading…
Cancel
Save