mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 13:24:47 +00:00
fix: Get the exchange rate based on date.
This commit is contained in:
@@ -98,14 +98,15 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
|
||||
|
||||
if not value:
|
||||
import requests
|
||||
api_url = "https://api.exchangerate.host/latest"
|
||||
api_url = "https://api.exchangerate.host/convert"
|
||||
response = requests.get(api_url, params={
|
||||
"symbols": from_currency+","+to_currency,
|
||||
"base": from_currency
|
||||
"date": transaction_date,
|
||||
"from": from_currency,
|
||||
"to": to_currency
|
||||
})
|
||||
# expire in 6 hours
|
||||
response.raise_for_status()
|
||||
value = response.json()["rates"][to_currency]
|
||||
value = response.json()["result"]
|
||||
cache.setex(key, value, 6 * 60 * 60)
|
||||
return flt(value)
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user