From 81b91df36b9deceedb2ab297ff0f691660de418a Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 17 Mar 2020 17:50:09 +0100 Subject: [PATCH] [12.0][IMP] - Add failing test for creating contract grouped by contract template When creating a contract from SO, the systme should bgoup by contract template sale order lines and create one contract per contract template actually the system group by contract template but create as many contracts as many sale order lines. --- product_contract/tests/test_sale_order.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index f581aebce..b007f6dfd 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -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)