feat: button to restore default settings
This commit is contained in:
parent
227466c365
commit
06340ad08a
@ -2,7 +2,26 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Currency Exchange Settings', {
|
frappe.ui.form.on('Currency Exchange Settings', {
|
||||||
// refresh: function(frm) {
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -37,7 +37,7 @@ class CurrencyExchangeSettings(Document):
|
|||||||
to_currency=to_currency,
|
to_currency=to_currency,
|
||||||
from_currency=from_currency
|
from_currency=from_currency
|
||||||
)]
|
)]
|
||||||
except KeyError:
|
except Exception:
|
||||||
frappe.throw("Invalid result key. Response: " + response.text)
|
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."))
|
frappe.throw(_("Returned exchange rate is neither integer not float."))
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Key",
|
"label": "Key",
|
||||||
"reqd": 1,
|
"reqd": 1
|
||||||
"unique": 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "value",
|
"fieldname": "value",
|
||||||
@ -28,7 +27,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-09-04 11:24:21.944002",
|
"modified": "2021-09-04 17:49:17.383982",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Currency Exchange Settings Details",
|
"name": "Currency Exchange Settings Details",
|
||||||
|
@ -13,14 +13,13 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Key",
|
"label": "Key",
|
||||||
"reqd": 1,
|
"reqd": 1
|
||||||
"unique": 1
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-09-03 15:41:09.997576",
|
"modified": "2021-09-04 17:49:33.858070",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Currency Exchange Settings Result",
|
"name": "Currency Exchange Settings Result",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user