From fb19bd6938de9348eaaa35d8d20b617d3dab46c0 Mon Sep 17 00:00:00 2001 From: Arnaud Baes Date: Thu, 17 Oct 2019 08:11:12 +0000 Subject: [PATCH] [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) --- addons/mrp/models/product.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/product.py b/addons/mrp/models/product.py index cda455b02a9..6b3b54a2c61 100644 --- a/addons/mrp/models/product.py +++ b/addons/mrp/models/product.py @@ -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)