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'))