changeset 7d5951067ca3 in modules/product_cost_fifo:5.4
details:
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=7d5951067ca3
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 bf843f0ff958 -r 7d5951067ca3 move.py
--- a/move.py Sat Apr 04 16:39:05 2020 +0200
+++ b/move.py Fri Jun 19 00:24:56 2020 +0200
@@ -81,13 +81,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 bf843f0ff958 -r 7d5951067ca3 product.py
--- a/product.py Sat Apr 04 16:39:05 2020 +0200
+++ b/product.py Fri Jun 19 00:24:56 2020 +0200
@@ -30,7 +30,7 @@
self._domain_moves_cost,
('fifo_quantity_available', '>', 0),
('to_location.type', '=', 'storage'),
- ('from_location.type', 'in', ['supplier', 'production']),
+ ('from_location.type', '!=', 'storage'),
('to_location.type', '=', 'storage'),
], order=[('effective_date', 'DESC'), ('id', 'DESC')])