changeset 0e982f1af438 in modules/product_cost_fifo:5.2
details: 
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=0e982f1af438
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 d76ac598d344 -r 0e982f1af438 move.py
--- a/move.py   Sat Apr 04 17:09:36 2020 +0200
+++ b/move.py   Fri Jun 19 00:24:56 2020 +0200
@@ -51,13 +51,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 d76ac598d344 -r 0e982f1af438 product.py
--- a/product.py        Sat Apr 04 17:09:36 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')])

Reply via email to