mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] - Add unit test
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user