From 0c2b6fa7be8f33a1ab2ec213d304d6a81f7445b9 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Tue, 2 Apr 2024 12:35:42 +0200 Subject: [PATCH] [FIX] mrp: Handle kit with BoM having qty != 1 Use case: - Create a Kit BoM with finished qty to 5 consuming 10 components - Do a sale order for 3 units (3/5 of BoM) - Update the sale order line to 4 units Current behavior: The delivery has a huge amount to deliver Expected: The delivery is for 8 units It happens because the method `_compute_kit_quantities` always expect a BoM for 1 units. `bom_line_data['original_qty']` always contains the number of times the BoM will be needed and not the quantity of finished products. In order to have the number of component by unit of finished product we have to introduce the BoM quantity in the formula closes odoo/odoo#160149 Signed-off-by: Arnold Moyaux (arm) --- addons/mrp/models/stock_move.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index b3b4fb4cd85..d310ad45e52 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -545,6 +545,7 @@ class StockMove(models.Model): :return: The quantity delivered or received """ qty_ratios = [] + kit_qty = kit_qty / kit_bom.product_qty boms, bom_sub_lines = kit_bom.explode(product_id, kit_qty) for bom_line, bom_line_data in bom_sub_lines: # skip service since we never deliver them @@ -559,8 +560,8 @@ class StockMove(models.Model): # We compute the quantities needed of each components to make one kit. # Then, we collect every relevant moves related to a specific component # to know how many are considered delivered. - uom_qty_per_kit = bom_line_data['qty'] / bom_line_data['original_qty'] - qty_per_kit = bom_line.product_uom_id._compute_quantity(uom_qty_per_kit, bom_line.product_id.uom_id, round=False) + uom_qty_per_kit = bom_line_data['qty'] / (bom_line_data['original_qty']) + qty_per_kit = bom_line.product_uom_id._compute_quantity(uom_qty_per_kit / kit_bom.product_qty, bom_line.product_id.uom_id, round=False) if not qty_per_kit: continue incoming_moves = bom_line_moves.filtered(filters['incoming_moves'])