From 81591a34c29977f78825a687a6cf206a4eb7855a Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 4 Oct 2023 15:23:29 +0530 Subject: [PATCH 1/2] refactor: introduce access_key field --- .../currency_exchange_settings.json | 9 ++++++++- .../currency_exchange_settings.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json index c62b711f2c..df232a5848 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -9,6 +9,7 @@ "disabled", "service_provider", "api_endpoint", + "access_key", "url", "column_break_3", "help", @@ -84,12 +85,18 @@ "fieldname": "disabled", "fieldtype": "Check", "label": "Disabled" + }, + { + "depends_on": "eval:doc.service_provider == 'exchangerate.host';", + "fieldname": "access_key", + "fieldtype": "Data", + "label": "Access Key" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-01-09 12:19:03.955906", + "modified": "2023-10-04 15:30:25.333860", "modified_by": "Administrator", "module": "Accounts", "name": "Currency Exchange Settings", 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 d618c5ca11..117d5ff21e 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -18,11 +18,21 @@ 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( + frappe.bold(self.service_provider) + ) + ) + self.set("result_key", []) self.set("req_params", []) self.api_endpoint = "https://api.exchangerate.host/convert" self.append("result_key", {"key": "result"}) + self.append("req_params", {"key": "access_key", "value": self.access_key}) + self.append("req_params", {"key": "amount", "value": "1"}) self.append("req_params", {"key": "date", "value": "{transaction_date}"}) self.append("req_params", {"key": "from", "value": "{from_currency}"}) self.append("req_params", {"key": "to", "value": "{to_currency}"}) From c8e3dc6c4c6dbf248670fd553b39f6ba69232c2c Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 4 Oct 2023 17:18:26 +0530 Subject: [PATCH 2/2] chore: refactor test case for exchangerate.host provider --- .../setup/doctype/currency_exchange/test_currency_exchange.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py index 3b48c2b312..8477984c3c 100644 --- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py +++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py @@ -121,6 +121,7 @@ class TestCurrencyExchange(unittest.TestCase): # Update Currency Exchange Rate settings = frappe.get_single("Currency Exchange Settings") settings.service_provider = "exchangerate.host" + settings.access_key = "12345667890" settings.save() # Update exchange