Skip to content
Snippets Groups Projects
Commit c855038c authored by clesgow's avatar clesgow
Browse files

[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
parent 4ee3875a
No related branches found
No related tags found
No related merge requests found
...@@ -213,10 +213,10 @@ class ReportBomStructure(models.AbstractModel): ...@@ -213,10 +213,10 @@ class ReportBomStructure(models.AbstractModel):
continue continue
line_quantity = (current_quantity / (bom.product_qty or 1.0)) * line.product_qty line_quantity = (current_quantity / (bom.product_qty or 1.0)) * line.product_qty
if line.child_bom_id: 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, 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) index=new_index, product_info=product_info, ignore_stock=ignore_stock)
else: 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) components.append(component)
bom_report_line['bom_cost'] += component['bom_cost'] bom_report_line['bom_cost'] += component['bom_cost']
bom_report_line['components'] = components bom_report_line['components'] = components
......
...@@ -67,8 +67,8 @@ class ReportBomStructure(models.AbstractModel): ...@@ -67,8 +67,8 @@ class ReportBomStructure(models.AbstractModel):
@api.model @api.model
def _get_quantities_info(self, product, bom_uom, parent_bom, product_info): 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': 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 parent_product_id = self.env.context.get('parent_product_id', False)
route_info = product_info[parent_product.id].get(parent_bom.id, {}) route_info = product_info.get(parent_product_id, {}).get(parent_bom.id, {})
if route_info and route_info['route_type'] == 'subcontract': if route_info and route_info['route_type'] == 'subcontract':
subcontracting_loc = route_info['supplier'].partner_id.property_stock_subcontractor 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] subloc_product = product.with_context(location=subcontracting_loc.id, warehouse=False).read(['free_qty', 'qty_available'])[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment