changeset 896d141b6b7d in modules/product_cost_fifo:default
details: 
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset&node=896d141b6b7d
description:
        Use domain method to select incoming and outgoing move to recompute 
cost price

        issue10586
        review369311002
diffstat:

 product.py |  28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diffs (67 lines):

diff -r f24111710d40 -r 896d141b6b7d product.py
--- a/product.py        Sun Jul 04 17:54:47 2021 +0200
+++ b/product.py        Wed Jul 28 00:33:12 2021 +0200
@@ -99,21 +99,22 @@
             ('product', '=', self.id),
             self._domain_moves_cost(),
             ['OR',
-                [
-                    ('to_location.type', '=', 'storage'),
-                    ('from_location.type', '!=', 'storage'),
-                    ],
-                [
-                    ('from_location.type', '=', 'storage'),
-                    ('to_location.type', '!=', 'storage'),
-                    ],
-                ],
+                self._domain_in_moves_cost(),
+                self._domain_out_moves_cost(),
+                ]
             ]
         if start:
             domain.append(('effective_date', '>=', start))
         moves = Move.search(
                 domain, order=[('effective_date', 'ASC'), ('id', 'ASC')])
 
+        _in_moves = Move.search([
+                ('product', '=', self.id),
+                self._domain_moves_cost(),
+                self._domain_in_moves_cost(),
+                ], order=[])
+        _in_moves = set(m.id for m in _in_moves)
+
         revisions = Revision.get_for_product(self)
 
         cost_price = Decimal(0)
@@ -121,8 +122,7 @@
         if start:
             domain.remove(('effective_date', '>=', start))
             domain.append(('effective_date', '<', start))
-            domain.append(
-                ('from_location.type', 'in', ['supplier', 'production']))
+            domain.append(self._domain_in_moves_cost())
             prev_moves = Move.search(
                 domain,
                 order=[('effective_date', 'DESC'), ('id', 'DESC')],
@@ -135,10 +135,10 @@
                 quantity = Decimal(str(quantity))
 
         def in_move(move):
-            return move.to_location.type == 'storage'
+            return move.id in _in_moves
 
         def out_move(move):
-            return move.from_location.type == 'storage'
+            return not in_move(move)
 
         def compute_fifo_cost_price(quantity, date):
             fifo_moves = self.get_fifo_move(float(quantity), date=date)
@@ -195,7 +195,7 @@
                 revisions, cost_price, move.effective_date)
             qty = Uom.compute_qty(move.uom, move.quantity, self.default_uom)
             qty = Decimal(str(qty))
-            if move.from_location.type == 'storage':
+            if out_move(move):
                 qty *= -1
             if in_move(move):
                 unit_price = move.get_cost_price(product_cost_price=cost_price)

Reply via email to