From c6faec8a3da6eae603d00c6adc5b76a60e550c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 27 Sep 2020 16:46:23 +0200 Subject: [PATCH] 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 --- account.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/account.py b/account.py index 74fd22721f..de893e088c 100644 --- a/account.py +++ b/account.py @@ -196,8 +196,9 @@ class LandedCost(Workflow, ModelSQL, ModelView): 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 @@ class LandedCost(Workflow, ModelSQL, ModelView): 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 @@ class LandedCost(Workflow, ModelSQL, ModelView): 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: