mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
@@ -83,6 +83,7 @@ class SaleOrder(models.Model):
|
||||
'sale_order_line_id'
|
||||
)
|
||||
)
|
||||
contract_templates = self.env["contract.template"]
|
||||
for order_line in line_to_create_contract:
|
||||
contract_template = order_line.product_id.with_context(
|
||||
force_company=rec.company_id.id
|
||||
@@ -95,6 +96,8 @@ class SaleOrder(models.Model):
|
||||
rec.company_id.name
|
||||
)
|
||||
)
|
||||
contract_templates |= contract_template
|
||||
for contract_template in contract_templates:
|
||||
order_lines = line_to_create_contract.filtered(
|
||||
lambda r, template=contract_template:
|
||||
r.product_id.with_context(
|
||||
|
||||
@@ -357,3 +357,26 @@ class TestSaleOrder(TransactionCase):
|
||||
self.sale.action_draft()
|
||||
self.contract.is_terminated = False
|
||||
self.sale.action_draft()
|
||||
|
||||
def test_order_lines_with_the_same_contract_template(self):
|
||||
""" It should create one contract with two lines grouped by contract
|
||||
template"""
|
||||
self.product2.with_context(
|
||||
force_company=self.sale.company_id.id
|
||||
).write(
|
||||
{
|
||||
'is_contract': True,
|
||||
'property_contract_template_id': self.contract_template1.id,
|
||||
}
|
||||
)
|
||||
self.sale.order_line.onchange_product()
|
||||
self.sale.action_confirm()
|
||||
contracts = self.sale.order_line.mapped('contract_id')
|
||||
self.assertEqual(len(contracts), 1)
|
||||
self.assertEqual(len(contracts.contract_line_ids), 2)
|
||||
contracts = (
|
||||
self.env['contract.line']
|
||||
.search([('sale_order_line_id', 'in', self.sale.order_line.ids)])
|
||||
.mapped('contract_id')
|
||||
)
|
||||
self.assertEqual(len(contracts), 1)
|
||||
|
||||
Reference in New Issue
Block a user