From b054a9b9c8493d17e050fe1bdd76ed2187f8b47f Mon Sep 17 00:00:00 2001 From: Thibault Libioulle Date: Thu, 3 Nov 2022 15:17:43 +0000 Subject: [PATCH] [FIX] sale_mrp{,_margin}: fix dependency break on purchase_price This commit fixes premature usage of `purchase_price` field on sale.order.line model, before its definition in sale_margin module. Since this test requires both sale_mrp and sale_stock_margin to pass, this commit adds an auto-install bridge module that solely address this issue. Steps to reproduce: - Install sale_mrp module - Run tests (at least .test_kit_cost_calculation) Problem: Traceback: AttributeError: 'sale.order.line' object has no attribute 'purchase_price' See #100126 closes #104891 closes odoo/odoo#105458 X-original-commit: ac921c88909110deefa9b91be104244bda12458f Signed-off-by: Djamel Touati (otd) Co-authored-by: Thibault Libioulle --- addons/sale_mrp/tests/test_sale_mrp_flow.py | 43 --------------- addons/sale_mrp_margin/__init__.py | 2 + addons/sale_mrp_margin/__manifest__.py | 9 ++++ addons/sale_mrp_margin/tests/__init__.py | 4 ++ .../tests/test_sale_mrp_flow.py | 52 +++++++++++++++++++ doc/cla/corporate/aerospacelab.md | 16 ++++++ 6 files changed, 83 insertions(+), 43 deletions(-) create mode 100644 addons/sale_mrp_margin/__init__.py create mode 100644 addons/sale_mrp_margin/__manifest__.py create mode 100644 addons/sale_mrp_margin/tests/__init__.py create mode 100644 addons/sale_mrp_margin/tests/test_sale_mrp_flow.py create mode 100644 doc/cla/corporate/aerospacelab.md diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py index 108b386ca34..36885f57834 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_flow.py +++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py @@ -2077,49 +2077,6 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon): {'product_id': self.component_g.id, 'location_dest_id': stock_location.id, 'quantity_done': 40, 'state': 'done'}, ]) - def test_kit_cost_calculation(self): - """ Check that the average cost price is computed correctly after SO confirmation: - BOM 1: - - 1 unit of “super kit”: - - 2 units of “component a” - BOM 2: - - 1 unit of “component a”: - - 3 units of "component b" - 1 unit of "component b" = $10 - 1 unit of "super kit" = 2 * 3 * $10 = *$60 - """ - super_kit = self._cls_create_product('Super Kit', self.uom_unit) - (super_kit + self.component_a + self.component_b).categ_id.property_cost_method = 'average' - self.env['mrp.bom'].create({ - 'product_tmpl_id': self.component_a.product_tmpl_id.id, - 'product_qty': 1.0, - 'type': 'phantom', - 'bom_line_ids': [(0, 0, { - 'product_id': self.component_b.id, - 'product_qty': 3.0, - })] - }) - self.env['mrp.bom'].create({ - 'product_tmpl_id': super_kit.product_tmpl_id.id, - 'product_qty': 1.0, - 'type': 'phantom', - 'bom_line_ids': [(0, 0, { - 'product_id': self.component_a.id, - 'product_qty': 2.0, - })] - }) - self.component_b.standard_price = 10 - self.component_a.button_bom_cost() - super_kit.button_bom_cost() - so_form = Form(self.env['sale.order']) - so_form.partner_id = self.partner_a - with so_form.order_line.new() as line: - line.product_id = super_kit - so = so_form.save() - self.assertEqual(so.order_line.purchase_price, 60) - so.action_confirm() - self.assertEqual(so.order_line.purchase_price, 60) - def test_kit_decrease_sol_qty_to_zero(self): """ Create and confirm a SO with a kit product. Increasing/Decreasing the SOL qty diff --git a/addons/sale_mrp_margin/__init__.py b/addons/sale_mrp_margin/__init__.py new file mode 100644 index 00000000000..67dee8c60db --- /dev/null +++ b/addons/sale_mrp_margin/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. diff --git a/addons/sale_mrp_margin/__manifest__.py b/addons/sale_mrp_margin/__manifest__.py new file mode 100644 index 00000000000..31037ebf906 --- /dev/null +++ b/addons/sale_mrp_margin/__manifest__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Sale Mrp Margin", + 'category': 'Sales/Sales', + 'version': '0.1', + 'description': 'Handle BoM prices to compute sale margin.', + 'depends': ['sale_mrp', 'sale_stock_margin'], + 'license': 'LGPL-3', +} diff --git a/addons/sale_mrp_margin/tests/__init__.py b/addons/sale_mrp_margin/tests/__init__.py new file mode 100644 index 00000000000..69ebcfa6194 --- /dev/null +++ b/addons/sale_mrp_margin/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_sale_mrp_flow diff --git a/addons/sale_mrp_margin/tests/test_sale_mrp_flow.py b/addons/sale_mrp_margin/tests/test_sale_mrp_flow.py new file mode 100644 index 00000000000..b860e1da6ee --- /dev/null +++ b/addons/sale_mrp_margin/tests/test_sale_mrp_flow.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.sale_mrp.tests import test_sale_mrp_flow +from odoo.tests import common, Form + + +@common.tagged('post_install', '-at_install') +class TestSaleMrpFlow(test_sale_mrp_flow.TestSaleMrpFlow): + + def test_kit_cost_calculation(self): + """ Check that the average cost price is computed correctly after SO confirmation: + BOM 1: + - 1 unit of “super kit”: + - 2 units of “component a” + BOM 2: + - 1 unit of “component a”: + - 3 units of "component b" + 1 unit of "component b" = $10 + 1 unit of "super kit" = 2 * 3 * $10 = *$60 + """ + super_kit = self._cls_create_product('Super Kit', self.uom_unit) + (super_kit + self.component_a + self.component_b).categ_id.property_cost_method = 'average' + self.env['mrp.bom'].create({ + 'product_tmpl_id': self.component_a.product_tmpl_id.id, + 'product_qty': 1.0, + 'type': 'phantom', + 'bom_line_ids': [(0, 0, { + 'product_id': self.component_b.id, + 'product_qty': 3.0, + })] + }) + self.env['mrp.bom'].create({ + 'product_tmpl_id': super_kit.product_tmpl_id.id, + 'product_qty': 1.0, + 'type': 'phantom', + 'bom_line_ids': [(0, 0, { + 'product_id': self.component_a.id, + 'product_qty': 2.0, + })] + }) + self.component_b.standard_price = 10 + self.component_a.button_bom_cost() + super_kit.button_bom_cost() + so_form = Form(self.env['sale.order']) + so_form.partner_id = self.partner_a + with so_form.order_line.new() as line: + line.product_id = super_kit + so = so_form.save() + self.assertEqual(so.order_line.purchase_price, 60) + so.action_confirm() + self.assertEqual(so.order_line.purchase_price, 60) diff --git a/doc/cla/corporate/aerospacelab.md b/doc/cla/corporate/aerospacelab.md new file mode 100644 index 00000000000..c7f9ae5bfa6 --- /dev/null +++ b/doc/cla/corporate/aerospacelab.md @@ -0,0 +1,16 @@ +Belgium, 2022-11-03 + +Aerospacelab S.A. agrees to the terms of the Odoo Corporate Contributor License +Agreement v1.0. + +I declare that I am authorized and able to make this agreement and sign this +declaration. + +Signed, + +Thibault Libioulle thibault.libioulle@aerospacelab.be https://github.com/tli-asl + +List of contributors: + +Thibault Libioulle thibault.libioulle@aerospacelab.be https://github.com/tli-asl +Rémi Chauvenne remi.chauvenne@aerospacelab.be https://github.com/rch-asl