changeset 1635dd7c1f7f in modules/product_cost_fifo:default
details: 
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=1635dd7c1f7f
description:
        Store product cost price revision

        The "Modify Cost Price" wizard create a revision record for each 
template or
        product. The cost price re-computation methods apply those revisions at 
the
        beginning of their date.
        The stock accounting move is created and posted when the cost price is 
modified
        by the re-computation.

        issue8930
        review260751002
diffstat:

 product.py                                                |  14 +++++++++-----
 tests/scenario_product_cost_fifo_recompute_cost_price.rst |   4 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diffs (64 lines):

diff -r f3fcb65989bf -r 1635dd7c1f7f product.py
--- a/product.py        Sun Jan 26 15:29:23 2020 +0100
+++ b/product.py        Sun Jan 26 21:10:40 2020 +0100
@@ -95,6 +95,7 @@
         Move = pool.get('stock.move')
         Currency = pool.get('currency.currency')
         Uom = pool.get('product.uom')
+        Revision = pool.get('product.cost_price.revision')
         digits = self.__class__.cost_price.digits
 
         domain = [
@@ -116,6 +117,8 @@
         moves = Move.search(
                 domain, order=[('effective_date', 'ASC'), ('id', 'ASC')])
 
+        revisions = Revision.get_for_product(self)
+
         cost_price = Decimal(0)
         quantity = 0
         if start:
@@ -197,6 +200,8 @@
                 current_out_qty = 0
             current_moves.append(move)
 
+            cost_price = Revision.apply_up_to(
+                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':
@@ -237,12 +242,11 @@
                 dict(cost_price=fifo_cost_price))
             if quantity:
                 cost_price = (
-                    ((current_cost_price * (
-                                quantity + current_out_qty))
+                    ((cost_price * (quantity + current_out_qty))
                         - (fifo_cost_price * current_out_qty))
                     / quantity)
             else:
                 cost_price = Decimal(0)
-            current_cost_price = cost_price.quantize(
-                Decimal(str(10.0 ** -digits[1])))
-        return current_cost_price
+        for revision in revisions:
+            cost_price = revision.get_cost_price(cost_price)
+        return cost_price
diff -r f3fcb65989bf -r 1635dd7c1f7f 
tests/scenario_product_cost_fifo_recompute_cost_price.rst
--- a/tests/scenario_product_cost_fifo_recompute_cost_price.rst Sun Jan 26 
15:29:23 2020 +0100
+++ b/tests/scenario_product_cost_fifo_recompute_cost_price.rst Sun Jan 26 
21:10:40 2020 +0100
@@ -110,7 +110,7 @@
 
     >>> product.reload()
     >>> product.cost_price
-    Decimal('99.9999')
+    Decimal('99.9998')
 
 Recompute cost price from a date::
 
@@ -123,4 +123,4 @@
 
     >>> product.reload()
     >>> product.cost_price
-    Decimal('99.9999')
+    Decimal('99.9998')

Reply via email to