mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[FIX] mrp_bom_attribute_match: structure and cost report
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
from . import models
|
from . import models
|
||||||
|
from . import reports
|
||||||
|
|||||||
1
mrp_bom_attribute_match/reports/__init__.py
Normal file
1
mrp_bom_attribute_match/reports/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import mrp_report_bom_structure
|
||||||
44
mrp_bom_attribute_match/reports/mrp_report_bom_structure.py
Normal file
44
mrp_bom_attribute_match/reports/mrp_report_bom_structure.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
|
||||||
|
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import Command, models
|
||||||
|
|
||||||
|
|
||||||
|
class ReportBomStructure(models.AbstractModel):
|
||||||
|
_inherit = "report.mrp.report_bom_structure"
|
||||||
|
|
||||||
|
def _get_bom_lines(self, bom, bom_quantity, product, line_id, level):
|
||||||
|
# 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 = 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(product) or not line.component_template_id:
|
||||||
|
continue
|
||||||
|
line_product = bom._get_component_template_product(
|
||||||
|
line, product, 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]
|
||||||
|
components, total = super()._get_bom_lines(
|
||||||
|
bom, bom_quantity, product, line_id, level
|
||||||
|
)
|
||||||
|
# Replace any NewId value by the real record id
|
||||||
|
# Otherwise it's evaluated as False in some situations, and it may cause issues
|
||||||
|
if has_template_lines:
|
||||||
|
for component in components:
|
||||||
|
for key, value in component.items():
|
||||||
|
if isinstance(value, models.NewId):
|
||||||
|
component[key] = value.origin
|
||||||
|
return components, total
|
||||||
@@ -4,7 +4,7 @@ from odoo.tests import Form
|
|||||||
from .common import TestMrpBomAttributeMatchBase
|
from .common import TestMrpBomAttributeMatchBase
|
||||||
|
|
||||||
|
|
||||||
class TestMrpAttachmentMgmt(TestMrpBomAttributeMatchBase):
|
class TestMrpBomAttributeMatch(TestMrpBomAttributeMatchBase):
|
||||||
def test_bom_1(self):
|
def test_bom_1(self):
|
||||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||||
mrp_bom_form.product_tmpl_id = self.product_sword
|
mrp_bom_form.product_tmpl_id = self.product_sword
|
||||||
@@ -170,3 +170,18 @@ class TestMrpAttachmentMgmt(TestMrpBomAttributeMatchBase):
|
|||||||
)
|
)
|
||||||
with self.assertRaisesRegex(UserError, r"Recursion error! .+"):
|
with self.assertRaisesRegex(UserError, r"Recursion error! .+"):
|
||||||
test_bom_3.explode(self.product_9, 1)
|
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,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user