changeset c3ae246bac8d in modules/product_cost_fifo:5.6
details:
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=c3ae246bac8d
description:
Do not update average cost price if the quantity is negative
This is the same test done in Move._compute_product_cost_price. When
the stock
quantity is below zero, the average cost price should not change.
And we process the incoming move first in order to keep quantity
positive
where possible.
issue9484
review325801002
(grafted from d865960839f5f0da883a36c40d63d1e912f7f039)
diffstat:
product.py | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diffs (35 lines):
diff -r dd8b0967644a -r c3ae246bac8d product.py
--- a/product.py Wed Jul 01 22:36:49 2020 +0200
+++ b/product.py Wed Jul 29 23:50:03 2020 +0200
@@ -143,9 +143,7 @@
return move.from_location.type == 'storage'
def compute_fifo_cost_price(quantity, date):
- fifo_moves = self.get_fifo_move(
- float(quantity),
- date=current_moves[-1].effective_date)
+ fifo_moves = self.get_fifo_move(float(quantity), date=date)
cost_price = Decimal(0)
consumed_qty = 0
@@ -164,6 +162,11 @@
if consumed_qty:
return round_price(cost_price / Decimal(str(consumed_qty)))
+ # For each day, process the incoming moves first
+ # in order to keep quantity positive where possible
+ # We do not re-browse because we expect only small changes
+ moves = sorted(moves, key=lambda m: (
+ m.effective_date, out_move(m), m.id))
current_moves = []
current_out_qty = 0
current_cost_price = cost_price
@@ -186,7 +189,7 @@
m for m in out_moves
if m.cost_price != fifo_cost_price],
dict(cost_price=fifo_cost_price))
- if quantity:
+ if quantity > 0 and quantity + current_out_qty >= 0:
cost_price = (
((current_cost_price * (
quantity + current_out_qty))