[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) <nim@odoo.com> Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user