[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
This commit is contained in:
Simon Lejeune
2017-10-18 18:05:26 +02:00
parent faff276e92
commit f1d485db08
+1 -1
View File
@@ -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