From 8b6be83f70ea7b25dd7f66bd8889a5b92b3ec658 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 4 Apr 2019 12:05:39 +0000 Subject: [PATCH] [FIX] stock_account: zero quantity - Set up a stockable product for which the product category is FIFO / Perpetual - Create a PO for this product with a unit price of 100$ - Confirm the purchase order - Receive the item in stock - Create a SO for this product - Confirm the SO - Deliver the item - Unlock the delivery order and change the done quantity to 0 - Unlock the delivery order and change again the done quantity to a positive value A `ZeroDivisionError` is raised. Since `move.product_qty` is still zero, we fallback to `quantity`. opw-1963984 closes odoo/odoo#32421 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock_account/models/stock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 01278afee97..156ee0dedab 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -303,7 +303,7 @@ class StockMove(models.Model): if qty_to_take_on_candidates == 0: move.write({ 'value': -tmp_value if not quantity else move.value or -tmp_value, # outgoing move are valued negatively - 'price_unit': -tmp_value / move.product_qty, + 'price_unit': -tmp_value / (move.product_qty or quantity), }) elif qty_to_take_on_candidates > 0: last_fifo_price = new_standard_price or move.product_id.standard_price