Browse Source

[IMP] - link contract line and its successor in upsel case

pull/208/head
sbejaoui 6 years ago
committed by Thomas Binsfeld
parent
commit
6d7774885a
  1. 39
      product_contract/models/sale_order_line.py
  2. 19
      product_contract/tests/test_sale_order.py

39
product_contract/models/sale_order_line.py

@ -47,8 +47,8 @@ class SaleOrderLine(models.Model):
help="Repeat every (Days/Week/Month/Year)",
copy=False,
)
date_start = fields.Date(string='Date Start',)
date_end = fields.Date(string='Date End',)
date_start = fields.Date(string='Date Start')
date_end = fields.Date(string='Date End')
contract_line_id = fields.Many2one(
comodel_name="account.analytic.invoice.line",
@ -57,9 +57,7 @@ class SaleOrderLine(models.Model):
copy=False,
)
is_auto_renew = fields.Boolean(
string="Auto Renew",
related="product_id.is_auto_renew",
readonly=True,
string="Auto Renew", related="product_id.is_auto_renew", readonly=True
)
@api.onchange('product_id')
@ -107,23 +105,20 @@ class SaleOrderLine(models.Model):
'discount': self.discount,
'date_end': self.date_end,
'date_start': self.date_start or fields.Date.today(),
'recurring_next_date':
contract_line_env._compute_first_recurring_next_date(
self.date_start or fields.Date.today(),
self.recurring_invoicing_type,
self.recurring_rule_type,
self.recurring_interval,
),
'recurring_next_date': contract_line_env._compute_first_recurring_next_date(
self.date_start or fields.Date.today(),
self.recurring_invoicing_type,
self.recurring_rule_type,
self.recurring_interval,
),
'recurring_interval': self.recurring_interval,
'recurring_invoicing_type': self.recurring_invoicing_type,
'recurring_rule_type': self.recurring_rule_type,
'is_auto_renew': self.product_id.is_auto_renew,
'auto_renew_interval': self.product_id.auto_renew_interval,
'auto_renew_rule_type': self.product_id.auto_renew_rule_type,
'termination_notice_interval':
self.product_id.termination_notice_interval,
'termination_notice_rule_type':
self.product_id.termination_notice_rule_type,
'termination_notice_interval': self.product_id.termination_notice_interval,
'termination_notice_rule_type': self.product_id.termination_notice_rule_type,
'contract_id': contract.id,
'sale_order_line_id': self.id,
}
@ -133,10 +128,18 @@ class SaleOrderLine(models.Model):
contract_line_env = self.env['account.analytic.invoice.line']
contract_line = self.env['account.analytic.invoice.line']
for rec in self:
contract_line |= contract_line_env.create(
new_contract_line = contract_line_env.create(
rec._prepare_contract_line_values(contract)
)
rec.contract_line_id.stop(rec.date_start)
contract_line |= new_contract_line
if rec.contract_line_id:
rec.contract_line_id.stop(rec.date_start)
rec.contract_line_id.successor_contract_line_id = (
new_contract_line
)
new_contract_line.predecessor_contract_line_id = (
self.contract_line_id.id
)
return contract_line
@api.constrains('contract_id')

19
product_contract/tests/test_sale_order.py

@ -58,8 +58,7 @@ class TestSaleOrder(TransactionCase):
{
"name": "Test Contract 2",
"partner_id": self.sale.partner_id.id,
"pricelist_id":
self.sale.partner_id.property_product_pricelist.id,
"pricelist_id": self.sale.partner_id.property_product_pricelist.id,
"recurring_invoices": True,
"contract_type": "purchase",
"contract_template_id": self.contract_template1.id,
@ -129,10 +128,7 @@ class TestSaleOrder(TransactionCase):
self.order_line1.recurring_invoicing_type,
self.product1.recurring_invoicing_type,
)
self.assertEqual(
self.order_line1.date_end,
Date.to_date('2019-01-01'),
)
self.assertEqual(self.order_line1.date_end, Date.to_date('2019-01-01'))
def test_check_contract_sale_partner(self):
"""Can't link order line to a partner contract different then the
@ -214,6 +210,13 @@ class TestSaleOrder(TransactionCase):
self.assertEqual(
self.contract_line.date_end, Date.to_date("2018-06-01")
)
self.assertFalse(
self.contract_line.is_auto_renew
self.assertFalse(self.contract_line.is_auto_renew)
new_contract_line = self.env['account.analytic.invoice.line'].search(
[('sale_order_line_id', '=', self.order_line1.id)]
)
self.assertEqual(
self.contract_line.successor_contract_line_id, new_contract_line
)
self.assertEqual(
new_contract_line.predecessor_contract_line_id, self.contract_line
)
Loading…
Cancel
Save