changeset 727f93652466 in modules/product_cost_fifo:5.0
details:
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=727f93652466
description:
Use all moves to compute FIFO
We must consider any incoming moves (ex: inventory) for the computation
of the
FIFO otherwise the back computation to find first in moves does not
pick enough
moves. As not all incoming moves have a unit price, we use the current
cost
price as fallback.
Also in re-computation, the in or out move test should only rely on the
storage
location usage in order to properly compute the average cost.
issue9274
review321471002
(grafted from c6a604d35422b708e9bfc57a8eaf5aa364b5190c)
diffstat:
move.py | 16 +++++++++-------
product.py | 2 +-
2 files changed, 10 insertions(+), 8 deletions(-)
diffs (38 lines):
diff -r e10831af2e5c -r 727f93652466 move.py
--- a/move.py Sat Apr 04 17:55:48 2020 +0200
+++ b/move.py Fri Jun 19 00:24:56 2020 +0200
@@ -52,13 +52,15 @@
to_save = []
for move, move_qty in fifo_moves:
consumed_qty += move_qty
-
- with Transaction().set_context(date=move.effective_date):
- move_unit_price = Currency.compute(
- move.currency, move.unit_price,
- self.company.currency, round=False)
- move_unit_price = Uom.compute_price(move.uom, move_unit_price,
- move.product.default_uom)
+ if move.from_location.type in {'supplier', 'production'}:
+ with Transaction().set_context(date=move.effective_date):
+ move_unit_price = Currency.compute(
+ move.currency, move.unit_price,
+ self.company.currency, round=False)
+ move_unit_price = Uom.compute_price(
+ move.uom, move_unit_price, move.product.default_uom)
+ else:
+ move_unit_price = move.cost_price or 0
cost_price += move_unit_price * Decimal(str(move_qty))
move_qty = Uom.compute_qty(self.product.default_uom, move_qty,
diff -r e10831af2e5c -r 727f93652466 product.py
--- a/product.py Sat Apr 04 17:55:48 2020 +0200
+++ b/product.py Fri Jun 19 00:24:56 2020 +0200
@@ -50,7 +50,7 @@
moves = Move.search([
('product', '=', product.id),
('state', '=', 'done'),
- ('from_location.type', 'in', ['supplier', 'production']),
+ ('from_location.type', '!=', 'storage'),
('to_location.type', '=', 'storage'),
], offset=offset, limit=limit,
order=[('effective_date', 'DESC'), ('id', 'DESC')])