From c855038c73e2c964ef78b41090c35e3a07d30f9b Mon Sep 17 00:00:00 2001 From: clesgow <quwo@odoo.com> 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 Part-of: odoo/odoo#104893 --- 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 f5717d0d2422..a64869dabf16 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 a99f0fac1475..8320db56c859 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] -- GitLab