changeset 8a909205c706 in modules/account_stock_landed_cost:default
details: 
https://hg.tryton.org/modules/account_stock_landed_cost?cmd=changeset;node=8a909205c706
description:
        Use fixed date to make currency conversion

        The invoice currency date and the move effective date must be used when
        converting cost between currency.

        issue9608
        review326121002
diffstat:

 account.py |  17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diffs (41 lines):

diff -r f331d9b7c045 -r 8a909205c706 account.py
--- a/account.py        Thu Jul 09 10:21:06 2020 +0100
+++ b/account.py        Sun Sep 27 16:46:23 2020 +0200
@@ -196,8 +196,9 @@
         cost = Decimal(0)
 
         for line in self.invoice_lines:
-            cost += Currency.compute(line.invoice.currency, line.amount,
-                currency, round=False)
+            with Transaction().set_context(date=line.invoice.currency_date):
+                cost += Currency.compute(
+                    line.invoice.currency, line.amount, currency, round=False)
         return cost
 
     def allocate_cost_by_value(self):
@@ -215,8 +216,9 @@
         sum_value = 0
         unit_prices = {}
         for move in moves:
-            unit_price = Currency.compute(move.currency, move.unit_price,
-                currency, round=False)
+            with Transaction().set_context(date=move.effective_date):
+                unit_price = Currency.compute(
+                    move.currency, move.unit_price, currency, round=False)
             unit_prices[move.id] = unit_price
             sum_value += unit_price * Decimal(str(move.quantity))
 
@@ -268,9 +270,10 @@
 
         for cost in costs:
             move = cost['move']
-            unit_landed_cost = Currency.compute(
-                currency, cost['unit_landed_cost'],
-                move.currency, round=False)
+            with Transaction().set_context(date=move.effective_date):
+                unit_landed_cost = Currency.compute(
+                    currency, cost['unit_landed_cost'],
+                    move.currency, round=False)
             unit_landed_cost = round_price(
                 unit_landed_cost, rounding=ROUND_HALF_EVEN)
             if move.unit_landed_cost is None:

Reply via email to