From 8fd6f85169da859a7743dab389d8a3de9dd86cfe Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 13 Jan 2017 11:14:41 +0100 Subject: [PATCH] [FIX] product_extended: Compute from BoM The price suggested thanks to the "Compute from BoM" button only takes into account the price of the products listed in the BoM lines. In v9, there was a "Recursive" option that provided the possibility to compute the prices of all products implied in the BoM, recursively. This option has been removed since it was leading to a "black box" behavior that was unclear to the users. However, limiting the price computation to the BoM lines only is too restrictive since it doesn't even take into account the phantom BoMs. By using the `explode` method, we have access to: - all products not manufactured - all products manufactured which are not kits (phantom BoM) It means that the cost of manufactured products (not kits) should still be computed before the product itself. opw-697866 --- addons/product_extended/models/product.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/product_extended/models/product.py b/addons/product_extended/models/product.py index 5a785118891..11a7bdc07ef 100644 --- a/addons/product_extended/models/product.py +++ b/addons/product_extended/models/product.py @@ -36,11 +36,11 @@ class ProductProduct(models.Model): def _calc_price(self, bom): price = 0.0 workcenter_cost = 0.0 - for sbom in bom.bom_line_ids: - my_qty = sbom.product_qty + result, result2 = bom.explode(self, 1) + for sbom, sbom_data in result2: if not sbom.attribute_value_ids: # No attribute_value_ids means the bom line is not variant specific - price += sbom.product_id.uom_id._compute_price(sbom.product_id.standard_price, sbom.product_uom_id) * my_qty + price += sbom.product_id.uom_id._compute_price(sbom.product_id.standard_price, sbom.product_uom_id) * sbom_data['qty'] if bom.routing_id: total_cost = 0.0 for order in bom.routing_id.operation_ids: