From 9359e6e2ceeec0255cbc8e625bd98a9e9b8eb49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A0n=20Todorovich?= Date: Tue, 31 Jan 2023 10:32:24 -0300 Subject: [PATCH] [ADD] mrp_account_bom_attribute_match --- mrp_account_bom_attribute_match/README.rst | 1 + mrp_account_bom_attribute_match/__init__.py | 1 + .../__manifest__.py | 16 +++++++++ .../models/__init__.py | 1 + .../models/product_product.py | 34 +++++++++++++++++++ .../tests/__init__.py | 1 + .../test_mrp_account_bom_attribute_match.py | 23 +++++++++++++ mrp_bom_attribute_match/tests/common.py | 4 +-- .../tests/test_mrp_bom_attribute_match.py | 8 ++--- .../addons/mrp_account_bom_attribute_match | 1 + .../mrp_account_bom_attribute_match/setup.py | 6 ++++ 11 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 mrp_account_bom_attribute_match/README.rst create mode 100644 mrp_account_bom_attribute_match/__init__.py create mode 100644 mrp_account_bom_attribute_match/__manifest__.py create mode 100644 mrp_account_bom_attribute_match/models/__init__.py create mode 100644 mrp_account_bom_attribute_match/models/product_product.py create mode 100644 mrp_account_bom_attribute_match/tests/__init__.py create mode 100644 mrp_account_bom_attribute_match/tests/test_mrp_account_bom_attribute_match.py create mode 120000 setup/mrp_account_bom_attribute_match/odoo/addons/mrp_account_bom_attribute_match create mode 100644 setup/mrp_account_bom_attribute_match/setup.py diff --git a/mrp_account_bom_attribute_match/README.rst b/mrp_account_bom_attribute_match/README.rst new file mode 100644 index 000000000..f86ee85e1 --- /dev/null +++ b/mrp_account_bom_attribute_match/README.rst @@ -0,0 +1 @@ +TO BE GENERATED diff --git a/mrp_account_bom_attribute_match/__init__.py b/mrp_account_bom_attribute_match/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_account_bom_attribute_match/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_account_bom_attribute_match/__manifest__.py b/mrp_account_bom_attribute_match/__manifest__.py new file mode 100644 index 000000000..0171062e6 --- /dev/null +++ b/mrp_account_bom_attribute_match/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# @author Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "MRP Account BOM Attribute Match", + "summary": "Glue module between `mrp_account` and `mrp_bom_attribute_match`", + "version": "15.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["ivantodorovich"], + "website": "https://github.com/OCA/manufacture", + "license": "AGPL-3", + "category": "Manufacturing", + "depends": ["mrp_account", "mrp_bom_attribute_match"], + "auto_install": True, +} diff --git a/mrp_account_bom_attribute_match/models/__init__.py b/mrp_account_bom_attribute_match/models/__init__.py new file mode 100644 index 000000000..5c74c8c30 --- /dev/null +++ b/mrp_account_bom_attribute_match/models/__init__.py @@ -0,0 +1 @@ +from . import product_product diff --git a/mrp_account_bom_attribute_match/models/product_product.py b/mrp_account_bom_attribute_match/models/product_product.py new file mode 100644 index 000000000..7cb219164 --- /dev/null +++ b/mrp_account_bom_attribute_match/models/product_product.py @@ -0,0 +1,34 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# @author Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def _compute_bom_price(self, bom, boms_to_recompute=False, byproduct_bom=False): + # OVERRIDE to fill in the `line.product_id` if a component template is used. + # To avoid a complete override, we HACK the bom by replacing it with a virtual + # record, and modifying it's lines on-the-fly. + has_template_lines = bom and any( + line.component_template_id for line in bom.bom_line_ids + ) + if has_template_lines: + bom = bom.new(origin=bom) + to_ignore_line_ids = [] + for line in bom.bom_line_ids: + if line._skip_bom_line(self) or not line.component_template_id: + continue + line_product = bom._get_component_template_product( + line, self, line.product_id + ) + if not line_product: + to_ignore_line_ids.append(line.id) + continue + else: + line.product_id = line_product + if to_ignore_line_ids: + bom.bom_line_ids = [Command.unlink(id) for id in to_ignore_line_ids] + return super()._compute_bom_price(bom, boms_to_recompute, byproduct_bom) diff --git a/mrp_account_bom_attribute_match/tests/__init__.py b/mrp_account_bom_attribute_match/tests/__init__.py new file mode 100644 index 000000000..50455c9c1 --- /dev/null +++ b/mrp_account_bom_attribute_match/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_account_bom_attribute_match diff --git a/mrp_account_bom_attribute_match/tests/test_mrp_account_bom_attribute_match.py b/mrp_account_bom_attribute_match/tests/test_mrp_account_bom_attribute_match.py new file mode 100644 index 000000000..1aa9f7ffb --- /dev/null +++ b/mrp_account_bom_attribute_match/tests/test_mrp_account_bom_attribute_match.py @@ -0,0 +1,23 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# @author Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.mrp_bom_attribute_match.tests.common import ( + TestMrpBomAttributeMatchBase, +) + + +class TestMrpAccount(TestMrpBomAttributeMatchBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_bom_cost(self): + sword_cyan, sword_magenta = self.product_sword.product_variant_ids + plastic_cyan, plastic_magenta = self.product_plastic.product_variant_ids + plastic_cyan.standard_price = 1.00 + plastic_magenta.standard_price = 2.00 + sword_cyan.button_bom_cost() + sword_magenta.button_bom_cost() + self.assertEqual(sword_cyan.standard_price, 1.00) + self.assertEqual(sword_magenta.standard_price, 2.00) diff --git a/mrp_bom_attribute_match/tests/common.py b/mrp_bom_attribute_match/tests/common.py index 5307b8e18..65e082930 100644 --- a/mrp_bom_attribute_match/tests/common.py +++ b/mrp_bom_attribute_match/tests/common.py @@ -1,7 +1,7 @@ -from odoo.tests import Form, common +from odoo.tests import Form, TransactionCase -class TestMrpAttachmentMgmtBase(common.SavepointCase): +class TestMrpBomAttributeMatchBase(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() diff --git a/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py b/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py index 944d5a7ac..b2efabaaf 100644 --- a/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py +++ b/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py @@ -1,14 +1,10 @@ from odoo.exceptions import UserError, ValidationError from odoo.tests import Form -from .common import TestMrpAttachmentMgmtBase +from .common import TestMrpBomAttributeMatchBase -class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - +class TestMrpAttachmentMgmt(TestMrpBomAttributeMatchBase): def test_bom_1(self): mrp_bom_form = Form(self.env["mrp.bom"]) mrp_bom_form.product_tmpl_id = self.product_sword diff --git a/setup/mrp_account_bom_attribute_match/odoo/addons/mrp_account_bom_attribute_match b/setup/mrp_account_bom_attribute_match/odoo/addons/mrp_account_bom_attribute_match new file mode 120000 index 000000000..cb758dc5c --- /dev/null +++ b/setup/mrp_account_bom_attribute_match/odoo/addons/mrp_account_bom_attribute_match @@ -0,0 +1 @@ +../../../../mrp_account_bom_attribute_match \ No newline at end of file diff --git a/setup/mrp_account_bom_attribute_match/setup.py b/setup/mrp_account_bom_attribute_match/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_account_bom_attribute_match/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)