diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py index b8817c60572c4fa6445a649ff6c8b35ceebbd23c..cbd2bbbc719e07a5f3abceccce85ca0eba8a02b2 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -43,7 +43,6 @@ class CurrencyExchangeSettings(Document): def set_parameters_and_result(self): if self.service_provider == "exchangerate.host": - if not self.access_key: frappe.throw( _("Access Key is required for Service Provider: {0}").format( @@ -78,9 +77,7 @@ class CurrencyExchangeSettings(Document): transaction_date=nowdate(), to_currency="INR", from_currency="USD" ) - api_url = self.api_endpoint.format( - transaction_date=nowdate(), to_currency="INR", from_currency="USD" - ) + api_url = self.api_endpoint.format(transaction_date=nowdate(), to_currency="INR", from_currency="USD") try: response = requests.get(api_url, params=params) @@ -100,19 +97,19 @@ class CurrencyExchangeSettings(Document): ] except Exception: frappe.throw(_("Invalid result key. Response:") + " " + response.text) - if not isinstance(value, (int, float)): + if not isinstance(value, (int | float)): frappe.throw(_("Returned exchange rate is neither integer not float.")) self.url = response.url @frappe.whitelist() -def get_api_endpoint(service_provider: str = None, use_http: bool = False): +def get_api_endpoint(service_provider: str | None = None, use_http: bool = False): if service_provider and service_provider in ["exchangerate.host", "frankfurter.app"]: if service_provider == "exchangerate.host": api = "api.exchangerate.host/convert" elif service_provider == "frankfurter.app": - api = "frankfurter.app/{transaction_date}" + api = "api.frankfurter.app/{transaction_date}" protocol = "https://" if use_http: diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py index 35dfee4736b64c6f4961d9043c077c293fc05c46..61a0307a38f494c85fd09619faf9e183d2c44f6e 100644 --- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py +++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py @@ -48,6 +48,7 @@ def save_new_records(test_records): test_exchange_values = {"2015-12-15": "66.999", "2016-01-15": "65.1"} + # Removing API call from get_exchange_rate def patched_requests_get(*args, **kwargs): class PatchResponse: @@ -66,9 +67,9 @@ def patched_requests_get(*args, **kwargs): if kwargs["params"].get("date") and kwargs["params"].get("from") and kwargs["params"].get("to"): if test_exchange_values.get(kwargs["params"]["date"]): return PatchResponse({"result": test_exchange_values[kwargs["params"]["date"]]}, 200) - elif args[0].startswith("https://frankfurter.app") and kwargs.get("params"): + elif args[0].startswith("https://api.frankfurter.app") and kwargs.get("params"): if kwargs["params"].get("base") and kwargs["params"].get("symbols"): - date = args[0].replace("https://frankfurter.app/", "") + date = args[0].replace("https://api.frankfurter.app/", "") if test_exchange_values.get(date): return PatchResponse( {"rates": {kwargs["params"].get("symbols"): test_exchange_values.get(date)}}, 200 @@ -82,7 +83,7 @@ class TestCurrencyExchange(unittest.TestCase): def clear_cache(self): cache = frappe.cache() for date in test_exchange_values.keys(): - key = "currency_exchange_rate_{0}:{1}:{2}".format(date, "USD", "INR") + key = "currency_exchange_rate_{}:{}:{}".format(date, "USD", "INR") cache.delete(key) def tearDown(self): diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index 9b0c885e8aff0c7f147b46e23136dc572699d0aa..f7ed268389019623ee4f9bf34252da88ad1d3af6 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -106,7 +106,7 @@ def setup_currency_exchange(): ces.set("result_key", []) ces.set("req_params", []) - ces.api_endpoint = "https://frankfurter.app/{transaction_date}" + ces.api_endpoint = "https://api.frankfurter.app/{transaction_date}" ces.append("result_key", {"key": "rates"}) ces.append("result_key", {"key": "{to_currency}"}) ces.append("req_params", {"key": "base", "value": "{from_currency}"})