Skip to content

Commit

Permalink
[FIX] mrp: float division by zero
Browse files Browse the repository at this point in the history
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 odoo#38890

opw-2262540

closes odoo#52192

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information
nboulif committed Jun 3, 2020
1 parent 0e8f867 commit ab780a9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion addons/mrp/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -265,11 +265,17 @@ def _compute_kit_quantities(self, product_id, kit_qty, kit_bom, filters):
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'))
Expand Down

0 comments on commit ab780a9

Please sign in to comment.