summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorArnaud Baes <arb@odoo.com>2019-10-17 08:11:12 +0000
committerfw-bot <otis@odoo.com>2019-10-23 15:08:25 +0000
commitfb19bd6938de9348eaaa35d8d20b617d3dab46c0 (patch)
tree6cf744ff48ea867e8c4591f8c2d8d089d7b554cc /addons
parent0cb78fa0479a5a0bcb0b8066441d0141f991199b (diff)
[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>
Diffstat (limited to 'addons')
-rw-r--r--addons/mrp/models/product.py8
1 files 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)