Browse Source

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

pull/207/head
sbejaoui 6 years ago
parent
commit
54c3b17f63
  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 @api.model
def _contract_line_to_renew_domain(self): 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 [ return [
('is_auto_renew', '=', True), ('is_auto_renew', '=', True),
('date_end', '<=', date_ref),
('is_canceled', '=', False), ('is_canceled', '=', False),
('contract_id.recurring_invoices', '=', True), ('contract_id.recurring_invoices', '=', True),
] ]
@ -856,7 +852,16 @@ class AccountAnalyticInvoiceLine(models.Model):
@api.model @api.model
def cron_renew_contract_line(self): def cron_renew_contract_line(self):
domain = self._contract_line_to_renew_domain() 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() to_renew.renew()
@api.model @api.model

5
contract/tests/test_contract.py

@ -1256,7 +1256,10 @@ class TestContract(TestContractBase):
{'date_end': fields.Date.today() - relativedelta(months=2)} {'date_end': fields.Date.today() - relativedelta(months=2)}
) )
self.acct_line.copy( 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( to_renew = self.acct_line.search(
self.acct_line._contract_line_to_renew_domain() self.acct_line._contract_line_to_renew_domain()

Loading…
Cancel
Save