From 762f31bb210ff95efa552c10c672045bc5494977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A0n=20Todorovich?= Date: Tue, 31 Jan 2023 11:35:04 -0300 Subject: [PATCH] [FIX] mrp_bom_attribute_match: structure and cost report --- .../reports/mrp_report_bom_structure.py | 5 ++--- .../tests/test_mrp_bom_attribute_match.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) 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 4574d1d3c..3cb228911 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 models +from odoo import Command, models class ReportBomStructure(models.AbstractModel): @@ -30,8 +30,7 @@ class ReportBomStructure(models.AbstractModel): else: line.product_id = line_product if to_ignore_line_ids: - for to_ignore_line_id in to_ignore_line_ids: - bom.bom_line_ids = [(3, to_ignore_line_id, 0)] + bom.bom_line_ids = [Command.unlink(id) for id in to_ignore_line_ids] components, total = super()._get_bom_lines( bom, bom_quantity, product, line_id, level ) 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 a08ce3418..432eb04eb 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 @@ -4,7 +4,7 @@ from odoo.tests import Form from .common import TestMrpBomAttributeMatchBase -class TestMrpAttachmentMgmt(TestMrpBomAttributeMatchBase): +class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase): def test_bom_1(self): mrp_bom_form = Form(self.env["mrp.bom"]) mrp_bom_form.product_tmpl_id = self.product_sword @@ -154,3 +154,18 @@ class TestMrpAttachmentMgmt(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.id, + ) + self.assertEqual( + res["lines"]["components"][0]["parent_id"], + self.bom_id.id, + )