From 38dd25f471ffcd755f52a2bc727d629d17bdac72 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 26 Apr 2016 23:53:35 +0200 Subject: [PATCH] Avoid a division by zero --- mrp_average_cost/mrp.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mrp_average_cost/mrp.py b/mrp_average_cost/mrp.py index 4311ac5..e45239b 100644 --- a/mrp_average_cost/mrp.py +++ b/mrp_average_cost/mrp.py @@ -305,10 +305,13 @@ class MrpProduction(orm.Model): # so we consider that standard_price is in company currency # It will not work if you are in multi-company environment # with companies in different currencies - new_std_price = ( - (product.standard_price * qty_before_mo) + - (mo_standard_price * mo_qty_product_uom)) / \ - (qty_before_mo + mo_qty_product_uom) + if not qty_before_mo + mo_qty_product_uom: + new_std_price = mo_standard_price + else: + new_std_price = ( + (product.standard_price * qty_before_mo) + + (mo_standard_price * mo_qty_product_uom)) / \ + (qty_before_mo + mo_qty_product_uom) ctx_product = context.copy() ctx_product['product_price_history_origin'] = _( '%s (Qty before: %s - Added qty: %s - Unit price of '