Browse Source

[IMP] - Add unit test

pull/208/head
sbejaoui 6 years ago
committed by Thomas Binsfeld
parent
commit
6e9eeed179
  1. 20
      product_contract/models/contract_line.py
  2. 35
      product_contract/tests/test_sale_order.py

20
product_contract/models/contract_line.py

@ -23,3 +23,23 @@ class AccountAnalyticInvoiceLine(models.Model):
if self.sale_order_line_id and res:
res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])]
return res
@api.onchange('product_id')
def _onchange_product_id_recurring_info(self):
for rec in self:
rec.date_start = fields.Date.today()
if rec.product_id.is_contract:
rec.recurring_rule_type = rec.product_id.recurring_rule_type
rec.recurring_invoicing_type = (
rec.product_id.recurring_invoicing_type
)
rec.recurring_interval = rec.product_id.recurring_interval
rec.is_auto_renew = rec.product_id.is_auto_renew
rec.auto_renew_interval = rec.product_id.auto_renew_interval
rec.auto_renew_rule_type = rec.product_id.auto_renew_rule_type
rec.termination_notice_interval = (
rec.product_id.termination_notice_interval
)
rec.termination_notice_rule_type = (
rec.product_id.termination_notice_rule_type
)

35
product_contract/tests/test_sale_order.py

@ -222,3 +222,38 @@ class TestSaleOrder(TransactionCase):
self.assertEqual(
new_contract_line.predecessor_contract_line_id, self.contract_line
)
def test_onchange_product_id_recurring_info(self):
self.product2.write(
{
'recurring_rule_type': 'monthly',
'recurring_invoicing_type': 'pre-paid',
'recurring_interval': '2',
'is_auto_renew': True,
'auto_renew_interval': '6',
'auto_renew_rule_type': 'monthly',
'termination_notice_interval': '6',
'termination_notice_rule_type': 'weekly',
}
)
self.contract_line.write(
{
'date_start': Date.today(),
'date_end': Date.today() + relativedelta(years=1),
'recurring_next_date': Date.today(),
'product_id': self.product2.id,
}
)
self.contract_line._onchange_product_id_recurring_info()
self.assertEqual(self.contract_line.recurring_rule_type, 'monthly')
self.assertEqual(
self.contract_line.recurring_invoicing_type, 'pre-paid'
)
self.assertEqual(self.contract_line.recurring_interval, 2)
self.assertEqual(self.contract_line.is_auto_renew, True)
self.assertEqual(self.contract_line.auto_renew_interval, 6)
self.assertEqual(self.contract_line.auto_renew_rule_type, 'monthly')
self.assertEqual(self.contract_line.termination_notice_interval, 6)
self.assertEqual(
self.contract_line.termination_notice_rule_type, 'weekly'
)
Loading…
Cancel
Save