Skip to content

Commit

Permalink
Merge pull request #37365 from frappe/mergify/bp/version-13/pr-37355
Browse files Browse the repository at this point in the history
fix: change currency exchange API to api.frankfurter.app (backport #37355)
  • Loading branch information
ruthra-kumar authored Oct 5, 2023
2 parents b0708d2 + 40e4758 commit ee42b0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_exchange_rate(self):
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15", "for_selling")
self.assertFalse(exchange_rate == 60)
self.assertEqual(flt(exchange_rate, 3), 66.999)
self.assertEqual(flt(exchange_rate, 3), 66.894)

def test_exchange_rate_strict(self):
# strict currency settings
Expand All @@ -87,15 +87,15 @@ def test_exchange_rate_strict(self):

self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying")
self.assertEqual(flt(exchange_rate, 3), 67.235)
self.assertEqual(flt(exchange_rate, 3), 67.79)

exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_selling")
self.assertEqual(exchange_rate, 62.9)

# Exchange rate as on 15th Dec, 2015
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15", "for_buying")
self.assertEqual(flt(exchange_rate, 3), 66.999)
self.assertEqual(flt(exchange_rate, 3), 66.894)

def test_exchange_rate_strict_switched(self):
# Start with allow_stale is True
Expand All @@ -108,4 +108,4 @@ def test_exchange_rate_strict_switched(self):
# Will fetch from fixer.io
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying")
self.assertEqual(flt(exchange_rate, 3), 67.235)
self.assertEqual(flt(exchange_rate, 3), 67.79)
9 changes: 4 additions & 5 deletions erpnext/setup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
if not value:
import requests

api_url = "https://api.exchangerate.host/convert"
response = requests.get(
api_url, params={"date": transaction_date, "from": from_currency, "to": to_currency}
)
api_url = f"https://api.frankfurter.app/{transaction_date}"
response = requests.get(api_url, params={"from": from_currency, "to": to_currency})

# expire in 6 hours
response.raise_for_status()
value = response.json()["result"]
value = response.json()["rates"][to_currency]
cache.setex(name=key, time=21600, value=flt(value))
return flt(value)
except Exception:
Expand Down

0 comments on commit ee42b0a

Please sign in to comment.