changeset b7d999ea82cd in modules/product_cost_fifo:default
details: 
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset&node=b7d999ea82cd
description:
        Save less often cost values when doing move

        We can save the cost values only when a cost value was computed for a 
product
        already moved.
        Also FIFO requires to save extra moves which can be included in the 
save loop
        so the Move._do method returns an extra list of moves to save.

        issue10640
        review369361002
diffstat:

 move.py |  12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diffs (41 lines):

diff -r 896d141b6b7d -r b7d999ea82cd move.py
--- a/move.py   Wed Jul 28 00:33:12 2021 +0200
+++ b/move.py   Fri Aug 27 08:59:26 2021 +0200
@@ -89,9 +89,6 @@
             assert move.quantity >= move.fifo_quantity - move.uom.rounding
             move.fifo_quantity = min(move.fifo_quantity, move.quantity)
             to_save.append(move)
-        if to_save:
-            # TODO save in do method when product change
-            self.__class__.save(to_save)
 
         if consumed_qty:
             cost_price = cost_price / Decimal(str(consumed_qty))
@@ -107,10 +104,10 @@
             cost_price = round_price(cost_price)
         else:
             cost_price = average_cost_price
-        return cost_price, average_cost_price
+        return cost_price, average_cost_price, to_save
 
     def _do(self):
-        cost_price = super(Move, self)._do()
+        cost_price, to_save = super(Move, self)._do()
         if (self.from_location.type != 'storage'
                 and self.to_location.type == 'storage'
                 and self.product.cost_price_method == 'fifo'):
@@ -122,11 +119,12 @@
         elif (self.from_location.type == 'storage'
                 and self.to_location.type != 'storage'
                 and self.product.cost_price_method == 'fifo'):
-            fifo_cost_price, cost_price = (
+            fifo_cost_price, cost_price, moves = (
                 self._update_fifo_out_product_cost_price())
             if self.cost_price_required and self.cost_price is None:
                 self.cost_price = fifo_cost_price
-        return cost_price
+            to_save.extend(moves)
+        return cost_price, to_save
 
     @classmethod
     @ModelView.button

Reply via email to