From 455ef6f0840bf108c379b29fd84e667cfca289d9 Mon Sep 17 00:00:00 2001 From: Kavin <78342682+kavin0411@users.noreply.github.com> Date: Fri, 10 Jan 2025 18:20:47 +0530 Subject: [PATCH] fix: calculate AED exchange rate based on pegged value with USD --- erpnext/setup/utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 13759ff8f58..b8c095f892a 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -50,6 +50,12 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No return if from_currency == to_currency: return 1 + # as AED is pegged to USD at the exchange rate of 3.6725 AED + # handling the exchange rate manually without API call + if from_currency == "USD" and to_currency == "AED": + return 3.6725 + if from_currency == "AED" and to_currency == "USD": + return 1 / 3.6725 if not transaction_date: transaction_date = nowdate() @@ -93,8 +99,8 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No settings = frappe.get_cached_doc("Currency Exchange Settings") req_params = { "transaction_date": transaction_date, - "from_currency": from_currency, - "to_currency": to_currency, + "from_currency": from_currency if from_currency != "AED" else "USD", + "to_currency": to_currency if to_currency != "AED" else "USD", } params = {} for row in settings.req_params: @@ -106,6 +112,12 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No for res_key in settings.result_key: value = value[format_ces_api(str(res_key.key), req_params)] cache.setex(name=key, time=21600, value=flt(value)) + + if to_currency == "AED": + value *= 3.6725 + if from_currency == "AED": + value /= 3.6725 + return flt(value) except Exception: frappe.log_error("Unable to fetch exchange rate")