mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[REF] contract: refactor _update_recurring_next_date
Reuse the logic that is now fully located in _get_recurring_next_date.
This commit is contained in:
committed by
Francisco Ivan Anton Prieto
parent
250c959f05
commit
92cb491f6b
@@ -675,23 +675,18 @@ class ContractLine(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def _update_recurring_next_date(self):
|
def _update_recurring_next_date(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
old_date = rec.recurring_next_date
|
last_date_invoiced = rec.next_period_date_end
|
||||||
new_date = old_date + self.get_relative_delta(
|
recurring_next_date = rec._get_recurring_next_date(
|
||||||
rec.recurring_rule_type, rec.recurring_interval
|
last_date_invoiced + relativedelta(days=1),
|
||||||
|
rec.recurring_invoicing_type,
|
||||||
|
rec.recurring_rule_type,
|
||||||
|
rec.recurring_interval,
|
||||||
|
max_date_end=rec.date_end,
|
||||||
)
|
)
|
||||||
if rec.recurring_rule_type == 'monthlylastday':
|
rec.write({
|
||||||
last_date_invoiced = old_date
|
"recurring_next_date": recurring_next_date,
|
||||||
elif rec.recurring_invoicing_type == 'post-paid':
|
"last_date_invoiced": last_date_invoiced,
|
||||||
last_date_invoiced = old_date - relativedelta(days=1)
|
})
|
||||||
elif rec.recurring_invoicing_type == 'pre-paid':
|
|
||||||
last_date_invoiced = new_date - relativedelta(days=1)
|
|
||||||
|
|
||||||
if rec.date_end and last_date_invoiced >= rec.date_end:
|
|
||||||
rec.last_date_invoiced = rec.date_end
|
|
||||||
rec.recurring_next_date = False
|
|
||||||
else:
|
|
||||||
rec.last_date_invoiced = last_date_invoiced
|
|
||||||
rec.recurring_next_date = new_date
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _init_last_date_invoiced(self):
|
def _init_last_date_invoiced(self):
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ class TestContract(TestContractBase):
|
|||||||
self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced)
|
self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced)
|
||||||
|
|
||||||
def test_contract_monthly_lastday(self):
|
def test_contract_monthly_lastday(self):
|
||||||
recurring_next_date = to_date('2018-03-31')
|
recurring_next_date = to_date('2018-02-28')
|
||||||
last_date_invoiced = to_date('2018-02-22')
|
last_date_invoiced = to_date('2018-02-22')
|
||||||
self.acct_line.recurring_next_date = '2018-02-22'
|
self.acct_line.recurring_next_date = '2018-02-22'
|
||||||
self.acct_line.recurring_invoicing_type = 'post-paid'
|
self.acct_line.recurring_invoicing_type = 'post-paid'
|
||||||
@@ -279,7 +279,7 @@ class TestContract(TestContractBase):
|
|||||||
)
|
)
|
||||||
self.contract.recurring_create_invoice()
|
self.contract.recurring_create_invoice()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.acct_line.recurring_next_date, to_date('2018-04-01')
|
self.acct_line.recurring_next_date, to_date('2018-3-16')
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.acct_line.last_date_invoiced, to_date('2018-02-28')
|
self.acct_line.last_date_invoiced, to_date('2018-02-28')
|
||||||
|
|||||||
Reference in New Issue
Block a user