feat: Increase number of supported currency exchanges (#26763)

* fix: update test suite to accodomate new currency exchange function

* feat: Increase number of supported currency exchanges

* fix: don't make api call when testing

* remove condition for test(being fixed in another pull request)
This commit is contained in:
Dany Robert
2021-08-25 21:15:44 +05:30
committed by GitHub
parent 0fe6995816
commit 7b9a23eb7a
2 changed files with 13 additions and 24 deletions

View File

@@ -93,21 +93,21 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
try:
cache = frappe.cache()
key = "currency_exchange_rate_{0}:{1}:{2}".format(transaction_date,from_currency, to_currency)
key = "currency_exchange_rate_{0}:{1}:{2}".format(transaction_date, from_currency, to_currency)
value = cache.get(key)
if not value:
import requests
api_url = "https://frankfurter.app/{0}".format(transaction_date)
api_url = "https://api.exchangerate.host/convert"
response = requests.get(api_url, params={
"base": from_currency,
"symbols": to_currency
"date": transaction_date,
"from": from_currency,
"to": to_currency
})
# expire in 6 hours
response.raise_for_status()
value = response.json()["rates"][to_currency]
cache.set_value(key, value, expires_in_sec=6 * 60 * 60)
value = response.json()["result"]
cache.setex(name=key, time=21600, value=flt(value))
return flt(value)
except:
frappe.log_error(title="Get Exchange Rate")