[FIX] stock: Support for optional components in kit

When a BoM is using a component with a quantity required set to 0,
tracebacks were occuring when computing the available quantities
for the kit.

Fixes #38807

closes odoo/odoo#39267

X-original-commit: 7676269ba56c8e293ef4cd3dffbe7eccbad4a9d0
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
Arnaud Baes
2019-10-23 15:08:25 +00:00
committed by fw-bot
parent 0cb78fa047
commit fb19bd6938
+5 -3
View File
@@ -3,7 +3,7 @@
from datetime import timedelta
from odoo import api, fields, models
from odoo.tools.float_utils import float_round
from odoo.tools.float_utils import float_round, float_is_zero
class ProductTemplate(models.Model):
@@ -119,8 +119,10 @@ class ProductProduct(models.Model):
ratios_free_qty = []
for bom_line, bom_line_data in bom_sub_lines:
component = bom_line.product_id
if component.type != 'product':
# Consumable product have 0 qty_available so we exclude them
if component.type != 'product' or 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. The same logic is applied to non-storable products as those
# products have 0 qty available.
continue
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)