[FIX] mrp_bom_attribute_match: fix unfolded print

Fix an error with the unfolded print of a BOM using
attribute matching.
This commit is contained in:
Alessandro Uffreduzzi
2024-06-14 15:57:01 +02:00
parent 1ee992a8e4
commit 61e1c31511

View File

@@ -1,7 +1,7 @@
# 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 models
from odoo import _, models
from odoo.tools import float_round
@@ -109,3 +109,88 @@ class ReportBomStructure(models.AbstractModel):
)
price += company.currency_id.round(not_rounded_price)
return price
def _get_pdf_line(
self,
bom_id,
product_id=False,
qty=1,
child_bom_ids=[], # noqa: B006
unfolded=False,
): # pylint: disable=dangerous-default-value
"""Override to tweak get_sub_lines and calculate product and child_bom"""
def get_sub_lines(bom, product_id, line_qty, line_id, level):
data = self._get_bom(
bom_id=bom.id,
product_id=product_id,
line_qty=line_qty,
line_id=line_id,
level=level,
)
bom_lines = data["components"]
lines = []
for bom_line in bom_lines:
lines.append(
{
"name": bom_line["prod_name"],
"type": "bom",
"quantity": bom_line["prod_qty"],
"uom": bom_line["prod_uom"],
"prod_cost": bom_line["prod_cost"],
"bom_cost": bom_line["total"],
"level": bom_line["level"],
"code": bom_line["code"],
"child_bom": bom_line["child_bom"],
"prod_id": bom_line["prod_id"],
}
)
if bom_line["child_bom"] and (
unfolded or bom_line["child_bom"] in child_bom_ids
):
line = self.env["mrp.bom.line"].browse(bom_line["line_id"])
# start difference
bom_product = self.env["product.product"].browse(int(product_id))
product = bom._get_component_template_product(
line, bom_product, line.product_id
)
child_bom = self.env["mrp.bom"].browse(bom_line["child_bom"])
lines += get_sub_lines(
child_bom, product.id, bom_line["prod_qty"], line, level + 1
)
# end difference
if data["operations"]:
lines.append(
{
"name": _("Operations"),
"type": "operation",
"quantity": data["operations_time"],
"uom": _("minutes"),
"bom_cost": data["operations_cost"],
"level": level,
}
)
for operation in data["operations"]:
if unfolded or "operation-" + str(bom.id) in child_bom_ids:
lines.append(
{
"name": operation["name"],
"type": "operation",
"quantity": operation["duration_expected"],
"uom": _("minutes"),
"bom_cost": operation["total"],
"level": level + 1,
}
)
return lines
bom = self.env["mrp.bom"].browse(bom_id)
product_id = (
product_id or bom.product_id.id or bom.product_tmpl_id.product_variant_id.id
)
data = self._get_bom(bom_id=bom_id, product_id=product_id, line_qty=qty)
pdf_lines = get_sub_lines(bom, product_id, qty, False, 1)
data["components"] = []
data["lines"] = pdf_lines
return data