[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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user