From 055f12e51abc1896b29b0988d81616b5fae0a1cb Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Fri, 29 May 2020 16:33:57 +0000 Subject: [PATCH] [FIX] mrp: float division by zero Cause When kit BOM line quantity is equal to zero in a sale order, it raise error because trying to divide bom_line_data['qty'] / bom_line_data['original_qty'] when computing kit quantities. Solution As BoMs allow components with 0 qty, a.k.a. optionnal components, we simply skip those to avoid a division by zero. Cherry-pick of #38890 opw-2262540 closes odoo/odoo#52362 X-original-commit: ab780a9d65e43f58a5745a5b92a25fb234827eb7 Signed-off-by: Nicolas Martinelli (nim) Signed-off-by: bon-odoo --- addons/mrp/models/stock_move.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 1f608376b5a..c60c9f051e6 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -3,7 +3,7 @@ from odoo import api, exceptions, fields, models, _ from odoo.exceptions import UserError -from odoo.tools import float_compare, float_round +from odoo.tools import float_compare, float_round, float_is_zero class StockMoveLine(models.Model): @@ -285,11 +285,17 @@ class StockMove(models.Model): for bom_line, bom_line_data in bom_sub_lines: bom_line_moves = self.filtered(lambda m: m.bom_line_id == bom_line) if bom_line_moves: + if float_is_zero(bom_line_data['qty'], precision_rounding=bom_line.product_uom_id.rounding): + # As BoMs allow components with 0 qty, a.k.a. optionnal components, we simply skip those + # to avoid a division by zero. + continue # 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) + if not qty_per_kit: + continue incoming_moves = bom_line_moves.filtered(filters['incoming_moves']) outgoing_moves = bom_line_moves.filtered(filters['outgoing_moves']) qty_processed = sum(incoming_moves.mapped('product_qty')) - sum(outgoing_moves.mapped('product_qty'))