From f1d485db08d18652c906b3fadc14e3db32947182 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Wed, 18 Oct 2017 17:08:23 +0200 Subject: [PATCH] [FIX] sale_stock: invoice policy on delivered quantities The created accounting entries have their debit/credit columns switched because - they use the sign of the value to post to decide if it should be credit or debit - an out move always have a negative sign As this code is always called on out moves, we can safely reverse the sign when getting the price_unit of the move. Fixes #20080 --- addons/sale_stock/models/account_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_stock/models/account_invoice.py b/addons/sale_stock/models/account_invoice.py index 930e5cf0bb2..4b9212beb8f 100644 --- a/addons/sale_stock/models/account_invoice.py +++ b/addons/sale_stock/models/account_invoice.py @@ -51,7 +51,7 @@ class AccountInvoiceLine(models.Model): qty_to_consider = invoiced_qty - qty_done qty_to_consider = min(qty_to_consider, quantity - qty_delivered) qty_delivered += qty_to_consider - average_price_unit = (average_price_unit * (qty_delivered - qty_to_consider) + move.price_unit * qty_to_consider) / qty_delivered + average_price_unit = (average_price_unit * (qty_delivered - qty_to_consider) + (-1 * move.price_unit) * qty_to_consider) / qty_delivered if qty_delivered == quantity: break return average_price_unit