Browse Source

[12.0][IMP] - extend contract line at renewal

pull/444/head
sbejaoui 5 years ago
parent
commit
61737ea920
  1. 8
      contract/models/contract_line.py
  2. 27
      contract/tests/test_contract.py

8
contract/models/contract_line.py

@ -1175,6 +1175,12 @@ class ContractLine(models.Model):
new_line._onchange_date_start()
return new_line
@api.multi
def _renew_extend_line(self, date_end):
self.ensure_one()
self.date_end = date_end
return self
@api.multi
def renew(self):
res = self.env['contract.line']
@ -1184,7 +1190,7 @@ class ContractLine(models.Model):
if company.create_new_line_at_contract_line_renew:
new_line = rec._renew_create_line(date_start, date_end)
else:
raise NotImplementedError
new_line = rec._renew_extend_line(date_end)
res |= new_line
msg = _(
"""Contract line for <strong>{product}</strong>

27
contract/tests/test_contract.py

@ -1669,7 +1669,7 @@ class TestContract(TestContractBase):
self.assertTrue(line_3.successor_contract_line_id)
self.assertFalse(line_4.successor_contract_line_id)
def test_renew(self):
def test_renew_create_new_line(self):
date_start = self.today - relativedelta(months=9)
date_end = (
date_start + relativedelta(months=12) - relativedelta(days=1)
@ -1694,6 +1694,31 @@ class TestContract(TestContractBase):
new_line.date_end, date_end + relativedelta(months=12)
)
def test_renew_extend_original_line(self):
self.contract.company_id.create_new_line_at_contract_line_renew = False
date_start = self.today - relativedelta(months=9)
date_end = (
date_start + relativedelta(months=12) - relativedelta(days=1)
)
self.acct_line.write(
{
'is_auto_renew': True,
'date_start': date_start,
'recurring_next_date': date_start,
'date_end': self.today,
}
)
self.acct_line._onchange_is_auto_renew()
self.assertEqual(self.acct_line.date_end, date_end)
self.acct_line.renew()
self.assertTrue(self.acct_line.is_auto_renew)
self.assertEqual(
self.acct_line.date_start, date_start
)
self.assertEqual(
self.acct_line.date_end, date_end + relativedelta(months=12)
)
def test_cron_recurring_create_invoice(self):
self.acct_line.date_start = '2018-01-01'
self.acct_line.recurring_invoicing_type = 'post-paid'

Loading…
Cancel
Save