44class ReportReplenishmentBomStructure (models .AbstractModel ):
55 _inherit = "report.mrp.report_bom_structure"
66
7+ @api .model
8+ def _get_subcontracting_line (self , bom , seller , level , bom_quantity ):
9+ """Override to convert seller price to the proper currency"""
10+ res = super ()._get_subcontracting_line (bom , seller , level , bom_quantity )
11+ currency = self .env .context .get ("force_currency" ) or self .env .company .currency_id
12+
13+ # Convert the seller price to the proper currency
14+ if bom .product_uom_id .ratio == 0 :
15+ raise ValueError (
16+ "El ratio de la unidad de medida del producto en el BOM es cero. "
17+ "Esto provocaría una división por cero. Verifique la configuración de la UoM."
18+ )
19+ ratio_uom_seller = seller .product_uom .ratio / bom .product_uom_id .ratio
20+ price = seller .currency_id ._convert (seller .price , currency , self .env .company , fields .Date .today (), round = True )
21+ res .update (
22+ {
23+ "prod_cost" : price / ratio_uom_seller * bom_quantity ,
24+ "bom_cost" : price / ratio_uom_seller * bom_quantity ,
25+ "currency" : currency ,
26+ "currency_id" : currency .id ,
27+ }
28+ )
29+
30+ return res
31+
732 @api .model
833 def _get_bom_data (
934 self ,
@@ -22,7 +47,7 @@ def _get_bom_data(
2247 ):
2348 """Here we use the replenishment cost for the uom unit"""
2449 if not self .env .context .get ("force_currency" ):
25- self = self .with_context (force_currency = product .currency_id )
50+ self = self .with_context (force_currency = product .currency_id if product else bom . product_tmpl_id . currency_id )
2651 res = super (ReportReplenishmentBomStructure , self )._get_bom_data (
2752 bom ,
2853 warehouse ,
@@ -43,6 +68,9 @@ def _get_bom_data(
4368 current_quantity = line_qty
4469 if bom_line :
4570 current_quantity = bom_line .product_uom_id ._compute_quantity (line_qty , bom .product_uom_id ) or 0
71+
72+ # Only update prod_cost (costo del producto final), not bom_cost
73+ # bom_cost is automatically calculated as: components + operations + subcontracting
4674 if not is_minimized :
4775 if product :
4876 price = product .uom_id ._compute_price (product .replenishment_cost , bom .product_uom_id ) * current_quantity
@@ -79,10 +107,13 @@ def _get_component_data(
79107 parent_bom , parent_product , warehouse , bom_line , line_quantity , level , index , product_info , ignore_stock
80108 )
81109 currency = self .env .context .get ("force_currency" ) or self .env .company .currency_id
82- price = (
83- bom_line .product_id .uom_id ._compute_price (bom_line .product_id .replenishment_cost , bom_line .product_uom_id )
84- * line_quantity
85- )
110+
111+ # Use replenishment_cost, if not defined use standard_price as fallback
112+ component_cost = bom_line .product_id .replenishment_cost
113+ if not component_cost :
114+ component_cost = bom_line .product_id .standard_price
115+
116+ price = bom_line .product_id .uom_id ._compute_price (component_cost , bom_line .product_uom_id ) * line_quantity
86117 price = bom_line .product_id .currency_id ._convert (
87118 price , currency , self .env .company , fields .Date .today (), round = True
88119 )
0 commit comments