From 4785cfcf6ce57f407260a22bedc2eb8b6e1982bb Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Wed, 23 Jun 2021 08:45:00 +0000 Subject: [PATCH] [FIX] mrp_account: fix reference to a deleted bom line - Enable Margin analysis - Have a product [TEST] in a category with - FIFO and Automated Valuation. - Kit BOM with 3 items (A,B,C) - Create a SO with [TEST] and confirm. - Modify the BOM and remove C from the kit. - Back to the SO, cancel it. Traceback will show, because there no more a bom_line associated with the move opw-2541674 closes odoo/odoo#72696 X-original-commit: 27821b728f409d7e1a69e84d0beb5ac708e6420e Signed-off-by: agr-odoo --- addons/mrp_account/models/product.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/mrp_account/models/product.py b/addons/mrp_account/models/product.py index 51f43ff9020..703bc163870 100644 --- a/addons/mrp_account/models/product.py +++ b/addons/mrp_account/models/product.py @@ -52,9 +52,13 @@ class ProductProduct(models.Model): value = 0 for move in stock_moves: bom_line = move.bom_line_id - bom_line_data = bom_lines[bom_line] - bom_line_qty = bom_line_data['qty'] - value += bom_line_qty * move.product_id._compute_average_price(qty_invoiced * bom_line_qty, qty_to_invoice * bom_line_qty, move) + if bom_line: + bom_line_data = bom_lines[bom_line] + line_qty = bom_line_data['qty'] + else: + # bom was altered (i.e. bom line removed) after being used + line_qty = move.product_qty + value += line_qty * move.product_id._compute_average_price(qty_invoiced * line_qty, qty_to_invoice * line_qty, move) return value def _compute_bom_price(self, bom, boms_to_recompute=False):