From e1a399e14bf53d315dd88650366b5aaa74890ecb Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 28 Oct 2019 17:52:30 +0100 Subject: [PATCH] [12.0][FIX] - contract company must be the same as the sale order When creating a contract from a sale order the company must be the sale order company and not the user company --- contract/models/abstract_contract.py | 2 +- product_contract/models/sale_order.py | 1 + product_contract/tests/test_sale_order.py | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/contract/models/abstract_contract.py b/contract/models/abstract_contract.py index 75dd9030..15a07c3d 100644 --- a/contract/models/abstract_contract.py +++ b/contract/models/abstract_contract.py @@ -14,7 +14,7 @@ class ContractAbstractContract(models.AbstractModel): _description = 'Abstract Recurring Contract' # These fields will not be synced to the contract - NO_SYNC = ['name', 'partner_id'] + NO_SYNC = ['name', 'partner_id', 'company_id'] name = fields.Char(required=True) # Needed for avoiding errors on several inherited behaviors diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 58f08249..a7f408c4 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -46,6 +46,7 @@ class SaleOrder(models.Model): template_name=contract_template.name, sale_name=self.name ), 'partner_id': self.partner_id.id, + 'company_id': self.company_id.id, 'contract_template_id': contract_template.id, 'user_id': self.user_id.id, 'payment_term_id': self.payment_term_id.id, diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 5c163510..7a630cbb 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -110,6 +110,19 @@ class TestSaleOrder(TransactionCase): contract_line.recurring_next_date, Date.to_date('2018-01-31') ) + def test_contract_company(self): + """ + contract company must be the sale order company and not the user one + """ + self.assertTrue(self.sale.company_id) + other_company = self.env['res.company'].create( + {'name': 'other company', 'parent_id': self.sale.company_id.id} + ) + self.sale.company_id = other_company + self.sale.action_confirm() + contracts = self.sale.order_line.mapped('contract_id') + self.assertEqual(contracts.mapped('company_id'), other_company) + def test_sale_order_invoice_status(self): """ sale line linked to contracts must not be invoiced from sale order