From 96fece1ff69371c4cf24f1f50d4625b3325a83e8 Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 4 Nov 2022 10:37:25 +0000 Subject: [PATCH] [FIX] mrp{,_subcontracting}: Add parent_product in bom overview Before this, when working on a bom with variants, when checking the parent from the component / child_bom, it would always take the first variant since it used the bom's product_template. This could lead to incorrect data when working with subcontracting, as when another variant from the first would be selected, when fetching quantities no parent info would be found as it would seek info from the first variant of the bom instead of the correct one. By doing this, we can now have the right variant and fetch the right informations. Part of task-2985735 X-original-commit: c855038c73e2c964ef78b41090c35e3a07d30f9b Part-of: odoo/odoo#106935 --- addons/mrp/report/mrp_report_bom_structure.py | 6 +++--- .../mrp_subcontracting/report/mrp_report_bom_structure.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/mrp/report/mrp_report_bom_structure.py b/addons/mrp/report/mrp_report_bom_structure.py index f5717d0d242..a64869dabf1 100644 --- a/addons/mrp/report/mrp_report_bom_structure.py +++ b/addons/mrp/report/mrp_report_bom_structure.py @@ -213,10 +213,10 @@ class ReportBomStructure(models.AbstractModel): continue line_quantity = (current_quantity / (bom.product_qty or 1.0)) * line.product_qty if line.child_bom_id: - component = self._get_bom_data(line.child_bom_id, warehouse, line.product_id, line_quantity, bom_line=line, level=level + 1, parent_bom=bom, - index=new_index, product_info=product_info, ignore_stock=ignore_stock) + component = self.with_context(parent_product_id=product.id)._get_bom_data(line.child_bom_id, warehouse, line.product_id, line_quantity, bom_line=line, level=level + 1, parent_bom=bom, + index=new_index, product_info=product_info, ignore_stock=ignore_stock) else: - component = self._get_component_data(bom, warehouse, line, line_quantity, level + 1, new_index, product_info, ignore_stock) + component = self.with_context(parent_product_id=product.id)._get_component_data(bom, warehouse, line, line_quantity, level + 1, new_index, product_info, ignore_stock) components.append(component) bom_report_line['bom_cost'] += component['bom_cost'] bom_report_line['components'] = components diff --git a/addons/mrp_subcontracting/report/mrp_report_bom_structure.py b/addons/mrp_subcontracting/report/mrp_report_bom_structure.py index a99f0fac147..8320db56c85 100644 --- a/addons/mrp_subcontracting/report/mrp_report_bom_structure.py +++ b/addons/mrp_subcontracting/report/mrp_report_bom_structure.py @@ -67,8 +67,8 @@ class ReportBomStructure(models.AbstractModel): @api.model def _get_quantities_info(self, product, bom_uom, parent_bom, product_info): if parent_bom and parent_bom.type == 'subcontract' and product.detailed_type == 'product': - parent_product = parent_bom.product_id or parent_bom.product_tmpl_id.product_variant_id - route_info = product_info[parent_product.id].get(parent_bom.id, {}) + parent_product_id = self.env.context.get('parent_product_id', False) + route_info = product_info.get(parent_product_id, {}).get(parent_bom.id, {}) if route_info and route_info['route_type'] == 'subcontract': subcontracting_loc = route_info['supplier'].partner_id.property_stock_subcontractor subloc_product = product.with_context(location=subcontracting_loc.id, warehouse=False).read(['free_qty', 'qty_available'])[0]