mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-20 18:54:55 +00:00
fix: calculate AED exchange rate based on pegged value with USD
(cherry picked from commit 455ef6f084)
This commit is contained in:
@@ -52,6 +52,12 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
|
|||||||
return
|
return
|
||||||
if from_currency == to_currency:
|
if from_currency == to_currency:
|
||||||
return 1
|
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:
|
if not transaction_date:
|
||||||
transaction_date = nowdate()
|
transaction_date = nowdate()
|
||||||
@@ -95,8 +101,8 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
|
|||||||
settings = frappe.get_cached_doc("Currency Exchange Settings")
|
settings = frappe.get_cached_doc("Currency Exchange Settings")
|
||||||
req_params = {
|
req_params = {
|
||||||
"transaction_date": transaction_date,
|
"transaction_date": transaction_date,
|
||||||
"from_currency": from_currency,
|
"from_currency": from_currency if from_currency != "AED" else "USD",
|
||||||
"to_currency": to_currency,
|
"to_currency": to_currency if to_currency != "AED" else "USD",
|
||||||
}
|
}
|
||||||
params = {}
|
params = {}
|
||||||
for row in settings.req_params:
|
for row in settings.req_params:
|
||||||
@@ -108,6 +114,12 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
|
|||||||
for res_key in settings.result_key:
|
for res_key in settings.result_key:
|
||||||
value = value[format_ces_api(str(res_key.key), req_params)]
|
value = value[format_ces_api(str(res_key.key), req_params)]
|
||||||
cache.setex(name=key, time=21600, value=flt(value))
|
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)
|
return flt(value)
|
||||||
except Exception:
|
except Exception:
|
||||||
frappe.log_error("Unable to fetch exchange rate")
|
frappe.log_error("Unable to fetch exchange rate")
|
||||||
|
|||||||
Reference in New Issue
Block a user