mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] - link contract line and its successor in upsel case
This commit is contained in:
committed by
Thomas Binsfeld
parent
4c7a314ef6
commit
6d7774885a
@@ -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,8 +105,7 @@ 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(
|
||||
'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,
|
||||
@@ -120,10 +117,8 @@ class SaleOrderLine(models.Model):
|
||||
'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)
|
||||
)
|
||||
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')
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user