diff --git a/sale_mrp_bom/README.rst b/sale_mrp_bom/README.rst index 56ce15cea4b..069f4a3b515 100644 --- a/sale_mrp_bom/README.rst +++ b/sale_mrp_bom/README.rst @@ -82,6 +82,10 @@ Trobz: * Hai Lang +Binhex: + +* Rolando Pérez + Other credits ~~~~~~~~~~~~~ diff --git a/sale_mrp_bom/readme/CONTRIBUTORS.rst b/sale_mrp_bom/readme/CONTRIBUTORS.rst index 83807955ca0..81c48eb569c 100644 --- a/sale_mrp_bom/readme/CONTRIBUTORS.rst +++ b/sale_mrp_bom/readme/CONTRIBUTORS.rst @@ -3,3 +3,7 @@ Trobz: * Hai Lang + +Binhex: + +* Rolando Pérez diff --git a/sale_mrp_bom/static/description/index.html b/sale_mrp_bom/static/description/index.html index 6f1ad3201dd..2b629673da6 100644 --- a/sale_mrp_bom/static/description/index.html +++ b/sale_mrp_bom/static/description/index.html @@ -426,6 +426,10 @@

Contributors

+

Binhex:

+

Other credits

diff --git a/sale_mrp_bom/tests/common.py b/sale_mrp_bom/tests/common.py new file mode 100644 index 00000000000..2db9cf043b1 --- /dev/null +++ b/sale_mrp_bom/tests/common.py @@ -0,0 +1,75 @@ +# Copyright 2024 Binhex Rolando Pérez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestSaleMrpBomCommon(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env.ref("base.res_partner_2") + cls.warehouse = cls.env.ref("stock.warehouse0") + route_manufacture = cls.warehouse.manufacture_pull_id.route_id.id + route_mto = cls.warehouse.mto_pull_id.route_id.id + cls.product_a = cls.create_product( + "Product A", route_ids=[(6, 0, [route_manufacture, route_mto])] + ) + cls.product_b = cls.create_product( + "Product B", route_ids=[(6, 0, [route_manufacture, route_mto])] + ) + cls.component_a = cls.create_product("Component A", route_ids=[]) + cls.component_b = cls.create_product("Component B", route_ids=[]) + cls.product_attr_color = cls.env["product.attribute"].create({"name": "Color"}) + cls.product_attr_val_red, cls.product_attr_val_green = cls.env[ + "product.attribute.value" + ].create( + [ + { + "name": "red", + "attribute_id": cls.product_attr_color.id, + "sequence": 1, + }, + { + "name": "blue", + "attribute_id": cls.product_attr_color.id, + "sequence": 2, + }, + ] + ) + + @classmethod + def create_product(cls, name, route_ids): + return cls.env["product.product"].create( + {"name": name, "type": "product", "route_ids": route_ids} + ) + + @classmethod + def create_sale_order(cls, client_ref): + return cls.env["sale.order"].create( + {"partner_id": cls.partner.id, "client_order_ref": client_ref} + ) + + @classmethod + def create_bom(cls, template): + return cls.env["mrp.bom"].create( + {"product_tmpl_id": template.id, "type": "normal"} + ) + + @classmethod + def create_bom_line(cls, bom, product, qty): + cls.env["mrp.bom.line"].create( + {"bom_id": bom.id, "product_id": product.id, "product_qty": qty} + ) + + @classmethod + def create_sale_order_line(cls, sale_order, product, qty, price, bom): + cls.env["sale.order.line"].create( + { + "order_id": sale_order.id, + "product_id": product.id, + "price_unit": price, + "product_uom_qty": qty, + "bom_id": bom.id, + } + ) diff --git a/sale_mrp_bom/tests/test_sale_mrp_bom.py b/sale_mrp_bom/tests/test_sale_mrp_bom.py index cddd34b8ed6..c6211d61a11 100644 --- a/sale_mrp_bom/tests/test_sale_mrp_bom.py +++ b/sale_mrp_bom/tests/test_sale_mrp_bom.py @@ -1,37 +1,24 @@ # Copyright 2020 Akretion Renato Lima +# Copyright 2024 Binhex Rolando Pérez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.exceptions import ValidationError -from odoo.tests.common import TransactionCase +from .common import TestSaleMrpBomCommon -class TestSaleMrpLink(TransactionCase): - def setUp(self): - super().setUp() - self.partner = self.env.ref("base.res_partner_2") - self.warehouse = self.env.ref("stock.warehouse0") - route_manufacture = self.warehouse.manufacture_pull_id.route_id.id - route_mto = self.warehouse.mto_pull_id.route_id.id - self.product_a = self._create_product( - "Product A", route_ids=[(6, 0, [route_manufacture, route_mto])] - ) - self.product_b = self._create_product( - "Product B", route_ids=[(6, 0, [route_manufacture, route_mto])] - ) - self.component_a = self._create_product("Component A", route_ids=[]) - self.component_b = self._create_product("Component B", route_ids=[]) - def _prepare_bom_lines(self): +class TestSaleMrpLink(TestSaleMrpBomCommon): + def prepare_boms(self): # Create BOMs - bom_a_v1 = self._create_bom(self.product_a.product_tmpl_id) - self._create_bom_line(bom_a_v1, self.component_a, 1) - bom_a_v2 = self._create_bom(self.product_a.product_tmpl_id) - self._create_bom_line(bom_a_v2, self.component_a, 2) + bom_a_v1 = self.create_bom(self.product_a.product_tmpl_id) + self.create_bom_line(bom_a_v1, self.component_a, 1) + bom_a_v2 = self.create_bom(self.product_a.product_tmpl_id) + self.create_bom_line(bom_a_v2, self.component_a, 2) - bom_b_v1 = self._create_bom(self.product_b.product_tmpl_id) - self._create_bom_line(bom_b_v1, self.component_b, 1) - bom_b_v2 = self._create_bom(self.product_b.product_tmpl_id) - self._create_bom_line(bom_b_v2, self.component_b, 2) + bom_b_v1 = self.create_bom(self.product_b.product_tmpl_id) + self.create_bom_line(bom_b_v1, self.component_b, 1) + bom_b_v2 = self.create_bom(self.product_b.product_tmpl_id) + self.create_bom_line(bom_b_v2, self.component_b, 2) bom_a, bom_b = bom_a_v2, bom_b_v2 self.boms = { @@ -40,50 +27,19 @@ def _prepare_bom_lines(self): } return bom_a, bom_b - def _prepare_so(self): - bom_a_v2, bom_b_v2 = self._prepare_bom_lines() + def prepare_so(self): + bom_a_v2, bom_b_v2 = self.prepare_boms() # Create Sale Order - so = self._create_sale_order(self.partner, "SO1") - self._create_sale_order_line(so, self.product_a, 1, 10.0, bom_a_v2) - self._create_sale_order_line(so, self.product_b, 1, 10.0, bom_b_v2) + so = self.create_sale_order("SO1") + self.create_sale_order_line(so, self.product_a, 1, 10.0, bom_a_v2) + self.create_sale_order_line(so, self.product_b, 1, 10.0, bom_b_v2) so.action_confirm() return so, bom_a_v2, bom_b_v2 - def _create_bom(self, template): - return self.env["mrp.bom"].create( - {"product_tmpl_id": template.id, "type": "normal"} - ) - - def _create_bom_line(self, bom, product, qty): - self.env["mrp.bom.line"].create( - {"bom_id": bom.id, "product_id": product.id, "product_qty": qty} - ) - - def _create_product(self, name, route_ids): - return self.env["product.product"].create( - {"name": name, "type": "product", "route_ids": route_ids} - ) - - def _create_sale_order(self, partner, client_ref): - return self.env["sale.order"].create( - {"partner_id": partner.id, "client_order_ref": client_ref} - ) - - def _create_sale_order_line(self, sale_order, product, qty, price, bom): - self.env["sale.order.line"].create( - { - "order_id": sale_order.id, - "product_id": product.id, - "price_unit": price, - "product_uom_qty": qty, - "bom_id": bom.id, - } - ) - def test_define_bom_in_sale_line(self): """Check manufactured order is created with BOM definied in Sale.""" - so, bom_a, bom_b = self._prepare_so() + so, bom_a, bom_b = self.prepare_so() # Check manufacture order mos = self.env["mrp.production"].search([("origin", "=", so.name)]) @@ -91,7 +47,7 @@ def test_define_bom_in_sale_line(self): self.assertEqual(mo.bom_id, self.boms.get(mo.product_id.id)) def test_pick_a_pack_confirm(self): - so, bom_a, bom_b = self._prepare_so() + so, bom_a, bom_b = self.prepare_so() picking, boms = so.picking_ids[0], (bom_a, bom_b) for i, line in enumerate(picking.move_lines): @@ -99,7 +55,7 @@ def test_pick_a_pack_confirm(self): self.assertEqual(values["bom_id"], boms[i]) def test_mismatch_product_variant_ids(self): - so, bom_a, bom_b = self._prepare_so() + so, bom_a, bom_b = self.prepare_so() line_a = so.order_line[0] self.assertEqual(line_a.bom_id, bom_a) with self.assertRaises(ValidationError): @@ -108,21 +64,17 @@ def test_mismatch_product_variant_ids(self): def test_accept_bom_with_no_variant(self): # make variants for template of product A product_tmpl_a = self.product_a.product_tmpl_id - prod_att_color = self.env["product.attribute"].create({"name": "Color"}) - product_attr_val_red, product_attr_val_green = self.env[ - "product.attribute.value" - ].create( - [ - {"name": "red", "attribute_id": prod_att_color.id, "sequence": 1}, - {"name": "blue", "attribute_id": prod_att_color.id, "sequence": 2}, - ] + prod_attr_color = self.product_attr_color + product_attr_val_red, product_attr_val_green = ( + self.product_attr_val_red, + self.product_attr_val_green, ) product_tmpl_a.attribute_line_ids = [ ( 0, 0, { - "attribute_id": prod_att_color.id, + "attribute_id": prod_attr_color.id, "value_ids": [ (6, 0, [product_attr_val_red.id, product_attr_val_green.id]) ], @@ -130,8 +82,8 @@ def test_accept_bom_with_no_variant(self): ) ] product_a = product_tmpl_a.product_variant_ids[0] - bom_no_variant = self._create_bom(product_tmpl_a) - so = self._create_sale_order(self.partner, "SO2") - self._create_sale_order_line(so, product_a, 2, 25, bom_no_variant) + bom_no_variant = self.create_bom(product_tmpl_a) + so = self.create_sale_order("SO2") + self.create_sale_order_line(so, product_a, 2, 25, bom_no_variant) line_a = so.order_line[0] line_a.bom_id = bom_no_variant