From 9ceb6b4f5996f962689ea671ea79ba81deeee763 Mon Sep 17 00:00:00 2001
From: clesgow <quwo@odoo.com>
Date: Fri, 4 Nov 2022 10:49:13 +0000
Subject: [PATCH] [FIX] mrp: avoid mixing up route_info

Take the following BoM :
Final_product
    Semi_final_1 (Subcontracted)
        Component_1 (Dropshipped to subcontractor)
    Semi_final_2 (Manufactured by us)
        Component_1 (Bought then put in stock)

Component_1 is used in both semi_finals, but in different contexts. For
Semi_final_1, it's directly dropshipped to the subcontractor, while for
Semi_final_2 we resupply our stock and then use it from there.

Problem is, since both components are the same, there was no distinction
made when fetching the data for the resupply methods. So if the first
case encountered was the dropship (like here), then for Semi_final_2 the
dropship would be used as well, while we're not in a subcontracting
context anymore.

Now we consider the parent_bom when fetching and storing the resupply
data, as different boms can have different contexts.

Part of task-2985735

Part-of: odoo/odoo#104893
---
 addons/mrp/report/mrp_report_bom_structure.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/addons/mrp/report/mrp_report_bom_structure.py b/addons/mrp/report/mrp_report_bom_structure.py
index 91c8344e3eb7..eb4dc5d153f3 100644
--- a/addons/mrp/report/mrp_report_bom_structure.py
+++ b/addons/mrp/report/mrp_report_bom_structure.py
@@ -248,7 +248,7 @@ class ReportBomStructure(models.AbstractModel):
         price = bom_line.product_id.uom_id._compute_price(bom_line.product_id.with_company(company).standard_price, bom_line.product_uom_id) * line_quantity
         rounded_price = company.currency_id.round(price)
 
-        bom_key = 'no_bom'
+        bom_key = parent_bom.id
         if not product_info[key].get(bom_key):
             product_info[key][bom_key] = self.with_context(product_info=product_info, parent_bom=parent_bom)._get_resupply_route_info(warehouse, bom_line.product_id, line_quantity)
         route_info = product_info[key].get(bom_key, {})
-- 
GitLab