diff --git a/mrp_account_bom_attribute_match/README.rst b/mrp_account_bom_attribute_match/README.rst index f86ee85e1..7bc1f7f1b 100644 --- a/mrp_account_bom_attribute_match/README.rst +++ b/mrp_account_bom_attribute_match/README.rst @@ -1 +1,83 @@ -TO BE GENERATED +=============================== +MRP Account BOM Attribute Match +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/15.0/mrp_account_bom_attribute_match + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-mrp_account_bom_attribute_match + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/manufacture&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Glue module between `mrp_bom_attribute_match` and `mrp_account`. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* `Camptocamp `_ + + * Iván Todorovich + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px + :target: https://github.com/ivantodorovich + :alt: ivantodorovich + +Current `maintainer `__: + +|maintainer-ivantodorovich| + +This module is part of the `OCA/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_account_bom_attribute_match/__manifest__.py b/mrp_account_bom_attribute_match/__manifest__.py index 0171062e6..0853e7c3a 100644 --- a/mrp_account_bom_attribute_match/__manifest__.py +++ b/mrp_account_bom_attribute_match/__manifest__.py @@ -5,7 +5,7 @@ { "name": "MRP Account BOM Attribute Match", "summary": "Glue module between `mrp_account` and `mrp_bom_attribute_match`", - "version": "15.0.1.0.0", + "version": "14.0.1.0.0", "author": "Camptocamp, Odoo Community Association (OCA)", "maintainers": ["ivantodorovich"], "website": "https://github.com/OCA/manufacture", diff --git a/mrp_account_bom_attribute_match/models/product_product.py b/mrp_account_bom_attribute_match/models/product_product.py index 7cb219164..4a8800777 100644 --- a/mrp_account_bom_attribute_match/models/product_product.py +++ b/mrp_account_bom_attribute_match/models/product_product.py @@ -2,13 +2,13 @@ # @author Iván Todorovich # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import Command, models +from odoo import models class ProductProduct(models.Model): _inherit = "product.product" - def _compute_bom_price(self, bom, boms_to_recompute=False, byproduct_bom=False): + def _compute_bom_price(self, bom, boms_to_recompute=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. @@ -30,5 +30,6 @@ class ProductProduct(models.Model): 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) + for to_ignore_line_id in to_ignore_line_ids: + bom.bom_line_ids = [(3, to_ignore_line_id, 0)] + return super()._compute_bom_price(bom, boms_to_recompute) diff --git a/mrp_account_bom_attribute_match/readme/DESCRIPTION.rst b/mrp_account_bom_attribute_match/readme/DESCRIPTION.rst index e69de29bb..2ae9ca8f4 100644 --- a/mrp_account_bom_attribute_match/readme/DESCRIPTION.rst +++ b/mrp_account_bom_attribute_match/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Glue module between `mrp_bom_attribute_match` and `mrp_account`. diff --git a/mrp_account_bom_attribute_match/static/description/index.html b/mrp_account_bom_attribute_match/static/description/index.html new file mode 100644 index 000000000..f1810d64b --- /dev/null +++ b/mrp_account_bom_attribute_match/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +MRP Account BOM Attribute Match + + + +
+

MRP Account BOM Attribute Match

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

Glue module between mrp_bom_attribute_match and mrp_account.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

ivantodorovich

+

This module is part of the OCA/manufacture project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mrp_account_bom_attribute_match/tests/__init__.py b/mrp_account_bom_attribute_match/tests/__init__.py index 50455c9c1..65b530c22 100644 --- a/mrp_account_bom_attribute_match/tests/__init__.py +++ b/mrp_account_bom_attribute_match/tests/__init__.py @@ -1 +1,2 @@ +from . import common 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 index 1aa9f7ffb..086c9f536 100644 --- 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 @@ -2,9 +2,7 @@ # @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, -) +from .common import TestMrpBomAttributeMatchBase class TestMrpAccount(TestMrpBomAttributeMatchBase): diff --git a/mrp_bom_attribute_match/reports/mrp_report_bom_structure.py b/mrp_bom_attribute_match/reports/mrp_report_bom_structure.py index 3cb228911..4574d1d3c 100644 --- a/mrp_bom_attribute_match/reports/mrp_report_bom_structure.py +++ b/mrp_bom_attribute_match/reports/mrp_report_bom_structure.py @@ -2,7 +2,7 @@ # @author Iván Todorovich # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import Command, models +from odoo import models class ReportBomStructure(models.AbstractModel): @@ -30,7 +30,8 @@ class ReportBomStructure(models.AbstractModel): 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] + for to_ignore_line_id in to_ignore_line_ids: + bom.bom_line_ids = [(3, to_ignore_line_id, 0)] components, total = super()._get_bom_lines( bom, bom_quantity, product, line_id, level ) diff --git a/mrp_bom_attribute_match/tests/common.py b/mrp_bom_attribute_match/tests/common.py index 12ef736ef..5307b8e18 100644 --- a/mrp_bom_attribute_match/tests/common.py +++ b/mrp_bom_attribute_match/tests/common.py @@ -1,172 +1,134 @@ -from odoo import Command -from odoo.models import BaseModel -from odoo.tests import Form, TransactionCase +from odoo.tests import Form, common -class TestMrpBomAttributeMatchBase(TransactionCase): +class TestMrpAttachmentMgmtBase(common.SavepointCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) - cls.warehouse = cls.env.ref("stock.warehouse0") - cls.route_manufacture = cls.warehouse.manufacture_pull_id.route_id - # Create products - cls.product_sword = cls.env["product.template"].create( + cls._create_products(cls) + cls._create_boms(cls) + + def _create_products(self): + self.warehouse = self.env.ref("stock.warehouse0") + route_manufacture = self.warehouse.manufacture_pull_id.route_id.id + self.product_sword = self.env["product.template"].create( { "name": "Plastic Sword", "type": "product", } ) - cls.product_surf = cls.env["product.template"].create( + self.product_surf = self.env["product.template"].create( { "name": "Surf", "type": "product", } ) - cls.product_fin = cls.env["product.template"].create( + self.product_fin = self.env["product.template"].create( { "name": "Surf Fin", "type": "product", } ) - cls.product_plastic = cls.env["product.template"].create( + self.product_plastic = self.env["product.template"].create( { "name": "Plastic Component", "type": "product", } ) - cls.p1 = cls.env["product.template"].create( + self.p1 = self.env["product.template"].create( { "name": "P1", "type": "product", - "route_ids": [Command.link(cls.route_manufacture.id)], + "route_ids": [(6, 0, [route_manufacture])], } ) - cls.p2 = cls.env["product.template"].create( + self.p2 = self.env["product.template"].create( { "name": "P2", "type": "product", - "route_ids": [Command.link(cls.route_manufacture.id)], + "route_ids": [(6, 0, [route_manufacture])], } ) - cls.p3 = cls.env["product.template"].create( + self.p3 = self.env["product.template"].create( { "name": "P3", "type": "product", - "route_ids": [Command.link(cls.route_manufacture.id)], + "route_ids": [(6, 0, [route_manufacture])], } ) - cls.product_9 = cls.env["product.product"].create( + self.product_9 = self.env["product.product"].create( { "name": "Paper", } ) - cls.product_10 = cls.env["product.product"].create( + self.product_10 = self.env["product.product"].create( { "name": "Stone", } ) - cls.product_attribute = cls.env["product.attribute"].create( + self.product_attribute = self.env["product.attribute"].create( {"name": "Colour", "display_type": "radio", "create_variant": "always"} ) - cls.attribute_value_ids = cls.env["product.attribute.value"].create( + self.attribute_value_ids = self.env["product.attribute.value"].create( [ - {"name": "Cyan", "attribute_id": cls.product_attribute.id}, - {"name": "Magenta", "attribute_id": cls.product_attribute.id}, + {"name": "Cyan", "attribute_id": self.product_attribute.id}, + {"name": "Magenta", "attribute_id": self.product_attribute.id}, ] ) - cls.plastic_attrs = cls.env["product.template.attribute.line"].create( + self.plastic_attrs = self.env["product.template.attribute.line"].create( { - "attribute_id": cls.product_attribute.id, - "product_tmpl_id": cls.product_plastic.id, - "value_ids": [Command.set(cls.product_attribute.value_ids.ids)], + "attribute_id": self.product_attribute.id, + "product_tmpl_id": self.product_plastic.id, + "value_ids": [(6, 0, self.product_attribute.value_ids.ids)], } ) - cls.sword_attrs = cls.env["product.template.attribute.line"].create( + self.sword_attrs = self.env["product.template.attribute.line"].create( { - "attribute_id": cls.product_attribute.id, - "product_tmpl_id": cls.product_sword.id, - "value_ids": [Command.set(cls.product_attribute.value_ids.ids)], + "attribute_id": self.product_attribute.id, + "product_tmpl_id": self.product_sword.id, + "value_ids": [(6, 0, self.product_attribute.value_ids.ids)], } ) - # Create boms - cls.bom_id = cls._create_bom( - cls.product_sword, - [ - dict( - component_template_id=cls.product_plastic.id, - product_qty=1, - ), - dict( - product_id=cls.product_9, - product_qty=1, - ), - ], - ) - cls.fin_bom_id = cls._create_bom( - cls.product_fin, - [ - dict( - product_id=cls.product_plastic.product_variant_ids[0], - product_qty=1, - ), - ], - ) - cls.surf_bom_id = cls._create_bom( - cls.product_surf, - [ - dict( - product_id=cls.product_fin.product_variant_ids[0], - product_qty=1, - ), - ], - ) - cls.p1_bom_id = cls._create_bom( - cls.p1, - [ - dict( - product_id=cls.p2.product_variant_ids[0], - product_qty=1, - ), - ], - ) - cls.p2_bom_id = cls._create_bom( - cls.p2, - [ - dict( - product_id=cls.p3.product_variant_ids[0], - product_qty=1, - ), - ], - ) - cls.p3_bom_id = cls._create_bom( - cls.p3, - [ - dict( - product_id=cls.p1.product_variant_ids[0], - product_qty=1, - ), - ], - ) - @classmethod - def _create_bom(cls, product, line_form_vals): - if product._name == "product.template": - template = product - product = cls.env["product.product"] - else: - template = product.product_tmpl_id - with Form(cls.env["mrp.bom"]) as form: - form.product_tmpl_id = template - form.product_id = product - for vals in line_form_vals: - with form.bom_line_ids.new() as line_form: - for key, value in vals.items(): - field = line_form._model._fields.get(key) - if field and field.relational: # pragma: no cover - if value and not isinstance(value, BaseModel): - value = cls.env[field.comodel_name].browse(value) - elif not value: - value = cls.env[field.comodel_name] - setattr(line_form, key, value) - return form.save() + def _create_boms(self): + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.product_sword + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.component_template_id = self.product_plastic + line_form.product_qty = 1 + self.bom_id = mrp_bom_form.save() + + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.product_fin + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.product_id = self.product_plastic.product_variant_ids[0] + line_form.product_qty = 1 + self.fin_bom_id = mrp_bom_form.save() + + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.product_surf + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.product_id = self.product_fin.product_variant_ids[0] + line_form.product_qty = 1 + self.surf_bom_id = mrp_bom_form.save() + + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.p1 + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.product_id = self.p2.product_variant_ids[0] + line_form.product_qty = 1 + self.p1_bom_id = mrp_bom_form.save() + + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.p2 + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.product_id = self.p3.product_variant_ids[0] + line_form.product_qty = 1 + self.p2_bom_id = mrp_bom_form.save() + + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.p3 + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.product_id = self.p1.product_variant_ids[0] + line_form.product_qty = 1 + self.p3_bom_id = mrp_bom_form.save() 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 d30a3e4c2..62a30adb1 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,10 +1,14 @@ from odoo.exceptions import UserError, ValidationError from odoo.tests import Form -from .common import TestMrpBomAttributeMatchBase +from .common import TestMrpAttachmentMgmtBase -class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase): +class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + def test_bom_1(self): mrp_bom_form = Form(self.env["mrp.bom"]) mrp_bom_form.product_tmpl_id = self.product_sword @@ -53,18 +57,18 @@ class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase): plastic_smells_like_orchid.unlink() def test_manufacturing_order_1(self): - sword_cyan = self.product_sword.product_variant_ids[0] - plastic_cyan = self.product_plastic.product_variant_ids[0] mo_form = Form(self.env["mrp.production"]) - mo_form.product_id = sword_cyan + mo_form.product_id = self.product_sword.product_variant_ids.filtered( + lambda x: x.display_name == "Plastic Sword (Cyan)" + ) mo_form.bom_id = self.bom_id mo_form.product_qty = 1 self.mo_sword = mo_form.save() self.mo_sword.action_confirm() # Assert correct component variant was selected automatically self.assertEqual( - self.mo_sword.move_raw_ids.product_id, - plastic_cyan + self.product_9, + self.mo_sword.move_raw_ids.product_id.display_name, + "Plastic Component (Cyan)", ) def test_manufacturing_order_2(self): @@ -154,22 +158,3 @@ class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase): ) with self.assertRaises(UserError): test_bom_3.explode(self.product_9, 1) - - def test_mrp_report_bom_structure(self): - sword_cyan = self.product_sword.product_variant_ids[0] - BomStructureReport = self.env["report.mrp.report_bom_structure"] - res = BomStructureReport._get_report_data(self.bom_id.id) - self.assertTrue(res["is_variant_applied"]) - self.assertEqual(res["lines"]["product"], sword_cyan) - self.assertEqual( - res["lines"]["components"][0]["line_id"], - self.bom_id.bom_line_ids[0].id, - ) - self.assertEqual( - res["lines"]["components"][1]["line_id"], - self.bom_id.bom_line_ids[1].id, - ) - self.assertEqual( - res["lines"]["components"][0]["parent_id"], - self.bom_id.id, - )