feat: Increase number of supported currency exchanges

Switch from frankfurter.app to exchange rate.host to accommodate more currency usage.
This commit is contained in:
Dany Robert 2021-06-28 19:01:52 +05:30 committed by GitHub
parent 3c97839826
commit e9bc2f354b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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