diff --git a/addons/mrp/report/mrp_report_bom_structure.py b/addons/mrp/report/mrp_report_bom_structure.py index 3e253feb3f4..ebff4ea6a1d 100644 --- a/addons/mrp/report/mrp_report_bom_structure.py +++ b/addons/mrp/report/mrp_report_bom_structure.py @@ -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])