mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] - filter by termination_notice for contract line to renew
This commit is contained in:
committed by
Francisco Ivan Anton Prieto
parent
5ffb2cffd8
commit
24027f0918
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user