From d9fc5bca7ecc6cdb5b1cc5242d79c429deabac27 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 14 May 2018 17:08:24 +0200 Subject: [PATCH] [FIX] purchase: move with zero qty - Create a product FIFO / Real-Time valuation - Create a PO with 1 unit, validate, receive the picking - Create the corresponding vendor bill, but do not validate - Unlock the picking and change the received quantity to 0.0 - Validate the invoice A traceback because of a zero division occurs. When searching for the stock moves linked to the PO, we should filter out the ones with a zero quantity. opw-1843543 --- addons/purchase/models/account_invoice.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index afd44e5f7db..23b3386fa9d 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -161,7 +161,10 @@ class AccountInvoice(models.Model): #for average/fifo/lifo costing method, fetch real cost price from incomming moves valuation_price_unit = i_line.purchase_line_id.product_uom._compute_price(i_line.purchase_line_id.price_unit, i_line.uom_id) stock_move_obj = self.env['stock.move'] - valuation_stock_move = stock_move_obj.search([('purchase_line_id', '=', i_line.purchase_line_id.id), ('state', '=', 'done')]) + valuation_stock_move = stock_move_obj.search([ + ('purchase_line_id', '=', i_line.purchase_line_id.id), + ('state', '=', 'done'), ('product_qty', '!=', 0.0) + ]) if self.type == 'in_refund': valuation_stock_move = valuation_stock_move.filtered(lambda m: m._is_out()) elif self.type == 'in_invoice':