feat: option for preconfigured selectable service providers
This commit is contained in:
parent
d869b3933b
commit
7291d9f236
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2021, Wahni Green 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"){
|
||||
frm.doc.api_endpoint = "https://api.exchangerate.host/convert";
|
||||
frm.clear_table("req_params")
|
||||
frm.clear_table("result_key")
|
||||
let params = {
|
||||
date: '{transaction_date}',
|
||||
from: '{from_currency}',
|
||||
to: '{to_currency}'
|
||||
}
|
||||
var row;
|
||||
$.each(params, function(key, value){
|
||||
row = frm.add_child("req_params");
|
||||
row.key = key;
|
||||
row.value = value;
|
||||
})
|
||||
row = frm.add_child("result_key");
|
||||
row.key = 'result';
|
||||
frm.refresh_fields();
|
||||
frm.save();
|
||||
}
|
||||
else if (frm.doc.service_provider == "Frankfurter.app"){
|
||||
frm.doc.api_endpoint = "https://frankfurter.app/{transaction_date}";
|
||||
frm.clear_table("req_params")
|
||||
frm.clear_table("result_key")
|
||||
var row;
|
||||
let result = ['rates', '{to_currency}']
|
||||
let params = {
|
||||
base: '{from_currency}',
|
||||
symbols: '{to_currency}'
|
||||
}
|
||||
$.each(params, function(key, value){
|
||||
row = frm.add_child("req_params");
|
||||
row.key = key;
|
||||
row.value = value;
|
||||
})
|
||||
$.each(result, function(key, value){
|
||||
row = frm.add_child("result_key");
|
||||
row.key = value;
|
||||
})
|
||||
frm.refresh_fields();
|
||||
frm.save();
|
||||
}
|
||||
}
|
||||
});
|
@ -6,6 +6,7 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"api_details_section",
|
||||
"service_provider",
|
||||
"api_endpoint",
|
||||
"url",
|
||||
"column_break_3",
|
||||
@ -16,6 +17,11 @@
|
||||
"result_key"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "api_details_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "API Details"
|
||||
},
|
||||
{
|
||||
"fieldname": "api_endpoint",
|
||||
"fieldtype": "Data",
|
||||
@ -23,15 +29,27 @@
|
||||
"label": "API Endpoint",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "url",
|
||||
"fieldtype": "Data",
|
||||
"label": "Example URL",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "help",
|
||||
"fieldtype": "HTML",
|
||||
"label": "Help",
|
||||
"options": "<h3>Currency Exchange Settings Help</h3>\n<p>There are 3 variables that could be used within the endpoint, result key and in values of the parameter.</p>\n<p>Exchange rate between {from_currency} and {to_currency} on {transaction_date} is fetched by the API.</p>\n<p>Example: If your endpoint is exchange.com/2021-08-01, then, you will have to input exchange.com/{transaction_date}</p>"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_2",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Request Parameters"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "req_params",
|
||||
"fieldtype": "Table",
|
||||
@ -40,12 +58,7 @@
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "api_details_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "API Details"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
@ -56,24 +69,19 @@
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "url",
|
||||
"fieldtype": "Data",
|
||||
"label": "Example URL",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "help",
|
||||
"fieldtype": "HTML",
|
||||
"label": "Help",
|
||||
"options": "<h3>Currency Exchange Settings Help</h3>\n<p>There are 3 variables that could be used within the endpoint, result key and in values of the parameter.</p>\n<p>Exchange rate between {from_currency} and {to_currency} on {transaction_date} is fetched by the API.</p>\n<p>Example: If your endpoint is exchange.com/2021-08-01, then, you will have to input exchange.com/{transaction_date}</p>"
|
||||
"fieldname": "service_provider",
|
||||
"fieldtype": "Select",
|
||||
"label": "Service Provider",
|
||||
"options": "Exchangerate.host\nFrankfurter.app\nCustom",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-04 11:41:34.375637",
|
||||
"modified": "2021-11-03 19:27:27.922353",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"module": "Accounts",
|
||||
"name": "Currency Exchange Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCurrencyExchangeSettings(unittest.TestCase):
|
||||
pass
|
@ -27,9 +27,9 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-04 17:49:17.383982",
|
||||
"modified": "2021-11-03 19:14:55.889037",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"module": "Accounts",
|
||||
"name": "Currency Exchange Settings Details",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
@ -19,9 +19,9 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-04 17:49:33.858070",
|
||||
"modified": "2021-11-03 19:14:40.054245",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"module": "Accounts",
|
||||
"name": "Currency Exchange Settings Result",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Currency Exchange Settings', {
|
||||
refresh: function(frm) {
|
||||
frm.add_custom_button(__('Restore Defaults'), function(){
|
||||
frm.doc.api_endpoint = "https://api.exchangerate.host/convert";
|
||||
frm.clear_table("req_params")
|
||||
frm.clear_table("result_key")
|
||||
let params = {
|
||||
date: '{transaction_date}',
|
||||
from: '{from_currency}',
|
||||
to: '{to_currency}'
|
||||
}
|
||||
var row;
|
||||
$.each(params, function(key, value){
|
||||
row = frm.add_child("req_params");
|
||||
row.key = key;
|
||||
row.value = value;
|
||||
})
|
||||
row = frm.add_child("result_key");
|
||||
row.key = 'result';
|
||||
frm.refresh_fields();
|
||||
frm.save();
|
||||
});
|
||||
}
|
||||
});
|
@ -1,8 +0,0 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCurrencyExchangeSettings(unittest.TestCase):
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user