fix: Cleanup and fixes
diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js
index a3a6561..6c40f2b 100644
--- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js
+++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js
@@ -1,9 +1,9 @@
-// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
+// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
 // For license information, please see license.txt
 
 frappe.ui.form.on('Currency Exchange Settings', {
 	service_provider: function(frm) {
-		if (frm.doc.service_provider == "Exchangerate.host") {
+		if (frm.doc.service_provider == "exchangerate.host") {
 			let result = ['result'];
 			let params = {
 				date: '{transaction_date}',
@@ -11,7 +11,7 @@
 				to: '{to_currency}'
 			};
 			add_param(frm, "https://api.exchangerate.host/convert", params, result);
-		} else if (frm.doc.service_provider == "Frankfurter.app") {
+		} else if (frm.doc.service_provider == "frankfurter.app") {
 			let result = ['rates', '{to_currency}'];
 			let params = {
 				base: '{from_currency}',
@@ -42,5 +42,4 @@
 	});
 
 	frm.refresh_fields();
-	frm.save();
 }
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 091102c..7921fcc 100644
--- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json
+++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json
@@ -1,6 +1,6 @@
 {
  "actions": [],
- "creation": "2021-09-02 14:53:50.923529",
+ "creation": "2022-01-10 13:03:26.237081",
  "doctype": "DocType",
  "editable_grid": 1,
  "engine": "InnoDB",
@@ -75,14 +75,14 @@
    "fieldname": "service_provider",
    "fieldtype": "Select",
    "label": "Service Provider",
-   "options": "Exchangerate.host\nFrankfurter.app\nCustom",
+   "options": "frankfurter.app\nexchangerate.host\nCustom",
    "reqd": 1
   }
  ],
  "index_web_pages_for_search": 1,
  "issingle": 1,
  "links": [],
- "modified": "2021-11-04 10:27:09.332768",
+ "modified": "2022-01-10 15:51:14.521174",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Currency Exchange Settings",
@@ -97,9 +97,30 @@
    "role": "System Manager",
    "share": 1,
    "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "role": "Accounts Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "role": "Accounts User",
+   "share": 1,
+   "write": 1
   }
  ],
  "sort_field": "modified",
  "sort_order": "DESC",
+ "states": [],
  "track_changes": 1
 }
\ No newline at end of file
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 e515542..c55e28b 100644
--- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py
+++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py
@@ -1,7 +1,8 @@
-# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
+# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
 # For license information, please see license.txt
 
 import frappe
+import requests
 from frappe import _
 from frappe.model.document import Document
 from frappe.utils import nowdate
@@ -9,38 +10,68 @@
 
 class CurrencyExchangeSettings(Document):
 	def validate(self):
-		transaction_date = nowdate()
-		from_currency = 'USD'
-		to_currency = 'INR'
+		self.set_parameters_and_result()
+		response, value = self.validate_parameters()
+		self.validate_result(response, value)
+
+	def set_parameters_and_result(self):
+		if self.service_provider == 'exchangerate.host':
+			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': 'date', 'value': '{transaction_date}'})
+			self.append('req_params', {'key': 'from', 'value': '{from_currency}'})
+			self.append('req_params', {'key': 'to', 'value': '{to_currency}'})
+		elif self.service_provider == 'frankfurter.app':
+			self.set('result_key', [])
+			self.set('req_params', [])
+
+			self.api_endpoint = "https://frankfurter.app/{transaction_date}"
+			self.append('result_key', {'key': 'rates'})
+			self.append('result_key', {'key': '{to_currency}'})
+			self.append('req_params', {'key': 'base', 'value': '{from_currency}'})
+			self.append('req_params', {'key': 'symbols', 'value': '{to_currency}'})
+
+	def validate_parameters(self):
 		params = {}
+
 		for row in self.req_params:
 			params[row.key] = row.value.format(
-				transaction_date=transaction_date,
-				to_currency=to_currency,
-				from_currency=from_currency
+				transaction_date=nowdate(),
+				to_currency='INR',
+				from_currency='USD'
 			)
-		import requests
+
 		api_url = self.api_endpoint.format(
-			transaction_date=transaction_date,
-			to_currency=to_currency,
-			from_currency=from_currency
+			transaction_date=nowdate(),
+			to_currency='INR',
+			from_currency='USD'
 		)
+
 		try:
 			response = requests.get(api_url, params=params)
 		except requests.exceptions.RequestException as e:
 			frappe.throw("Error: " + str(e))
+
 		response.raise_for_status()
 		value = response.json()
+
+		return response, value
+
+	def validate_result(self, response, value):
 		try:
 			for key in self.result_key:
 				value = value[str(key.key).format(
-					transaction_date=transaction_date,
-					to_currency=to_currency,
-					from_currency=from_currency
+					transaction_date=nowdate(),
+					to_currency='INR',
+					from_currency='USD'
 				)]
 		except Exception:
 			frappe.throw("Invalid result key. Response: " + response.text)
 		if not isinstance(value, (int, float)):
 			frappe.throw(_("Returned exchange rate is neither integer not float."))
+
 		self.url = response.url
 		frappe.msgprint("Exchange rate of USD to INR is " + str(value))
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index d9cedab..7f24273 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -317,4 +317,5 @@
 erpnext.patches.v14_0.migrate_crm_settings
 erpnext.patches.v13_0.rename_ksa_qr_field
 erpnext.patches.v13_0.disable_ksa_print_format_for_others # 16-12-2021
-erpnext.patches.v14_0.add_default_exit_questionnaire_notification_template
\ No newline at end of file
+erpnext.patches.v14_0.add_default_exit_questionnaire_notification_template
+erpnext.patches.v13_0.update_exchange_rate_settings
\ No newline at end of file
diff --git a/erpnext/patches/v13_0/update_exchange_rate_settings.py b/erpnext/patches/v13_0/update_exchange_rate_settings.py
new file mode 100644
index 0000000..6af93dc
--- /dev/null
+++ b/erpnext/patches/v13_0/update_exchange_rate_settings.py
@@ -0,0 +1,5 @@
+from erpnext.setup.install import setup_currency_exchange
+
+
+def execute():
+	setup_currency_exchange()
\ No newline at end of file
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index da39776..bafaab8 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -59,13 +59,20 @@
 				pass
 
 	frappe.db.set_default("date_format", "dd-mm-yyyy")
+
+	setup_currency_exchange()
+
+def setup_currency_exchange():
 	ces = frappe.get_single('Currency Exchange Settings')
 	try:
-		ces.api_endpoint = "https://api.exchangerate.host/convert"
-		ces.append('result_key', {'key': 'result'})
-		ces.append('req_params', {'key': 'date', 'value': '{transaction_date}'})
-		ces.append('req_params', {'key': 'from', 'value': '{from_currency}'})
-		ces.append('req_params', {'key': 'to', 'value': '{to_currency}'})
+		ces.set('result_key', [])
+		ces.set('req_params', [])
+
+		ces.api_endpoint = "https://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}'})
+		ces.append('req_params', {'key': 'symbols', 'value': '{to_currency}'})
 		ces.save()
 	except frappe.ValidationError:
 		pass
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index bfa26f2..4441bb9 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -100,7 +100,7 @@
 
 		if not value:
 			import requests
-			settings = frappe.get_single('Currency Exchange Settings')
+			settings = frappe.get_cached_doc('Currency Exchange Settings')
 			req_params = {
 				"transaction_date": transaction_date,
 				"from_currency": from_currency,