Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate AED exchange rate based on pegged value with USD #45215

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions erpnext/setup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down
Loading