From 1da808a125fd69b91dc868e6aec31165a461771d Mon Sep 17 00:00:00 2001 From: dsnetprofitxl <139927603+dsnetprofitxl@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:51:28 -0400 Subject: [PATCH 1/2] fix: change currency exchange API to api.frankfurter.app (cherry picked from commit 76919c4af2c127b19339fef9968dc3954e095d4c) --- erpnext/setup/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 5a019c68c9d3..5c7a56323741 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -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: From 40e475836e1f9a20be23c8b79037032c87ba5e27 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 4 Oct 2023 21:04:05 +0530 Subject: [PATCH 2/2] refactor(test): update exchange rate based on 'frankfurter' provider (cherry picked from commit a3fd4db45044efbe4e8b3844e5c62e57ab392549) --- .../doctype/currency_exchange/test_currency_exchange.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py index dcd06607c3ec..c598cdf9819e 100644 --- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py +++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py @@ -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 @@ -87,7 +87,7 @@ 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) @@ -95,7 +95,7 @@ def test_exchange_rate_strict(self): # 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 @@ -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)