[FIX] mrp: merge component line in BoM overview

This commit merges BoM overview's lines if they are about a same component.

Before this commit, if the BoM divided it's same components to use them
in different steps, the overview would separate them as well, which is wrong.

Task-3184663

X-original-commit: 37ac2e603f332dee1c4c18a105f070cb4ae9eda6
Part-of: odoo/odoo#121783
This commit is contained in:
Martin Maes
2023-05-23 16:31:52 +02:00
parent bf5ed6d9e8
commit d4de362b93
+19 -1
View File
@@ -218,7 +218,13 @@ class ReportBomStructure(models.AbstractModel):
parent_product=product, index=new_index, product_info=product_info, ignore_stock=ignore_stock)
else:
component = self._get_component_data(bom, product, warehouse, line, line_quantity, level + 1, new_index, product_info, ignore_stock)
components.append(component)
for component_bom in components:
if component['product_id'] == component_bom['product_id'] and component['uom'].id == component_bom['uom'].id:
self._merge_components(component_bom, component)
break
else:
components.append(component)
bom_report_line['bom_cost'] += component['bom_cost']
bom_report_line['components'] = components
bom_report_line['producible_qty'] = self._compute_current_production_capacity(bom_report_line)
@@ -601,3 +607,15 @@ class ReportBomStructure(models.AbstractModel):
@api.model
def _has_attachments(self, data):
return data['attachment_ids'] or any(self._has_attachments(component) for component in data.get('components', []))
@api.model
def _merge_components(self, component_1, component_2):
qty = component_2['quantity']
component_1["quantity"] = component_1["quantity"] + qty
component_1["base_bom_line_qty"] = component_1["quantity"] + qty
component_1["prod_cost"] = component_1["prod_cost"] + component_2["prod_cost"]
component_1["bom_cost"] = component_1["bom_cost"] + component_2["bom_cost"]
if not component_1.get("components"):
return
for index in range(len(component_1.get("components"))):
self._merge_components(component_1["components"][index], component_2["components"][index])