feat: button to restore default settings

This commit is contained in:
rtdany10 2021-09-04 17:53:51 +05:30
parent 227466c365
commit 06340ad08a
4 changed files with 27 additions and 10 deletions

View File

@ -2,7 +2,26 @@
// For license information, please see license.txt
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();
});
}
});

View File

@ -37,7 +37,7 @@ class CurrencyExchangeSettings(Document):
to_currency=to_currency,
from_currency=from_currency
)]
except KeyError:
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."))

View File

@ -14,8 +14,7 @@
"fieldtype": "Data",
"in_list_view": 1,
"label": "Key",
"reqd": 1,
"unique": 1
"reqd": 1
},
{
"fieldname": "value",
@ -28,7 +27,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-09-04 11:24:21.944002",
"modified": "2021-09-04 17:49:17.383982",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange Settings Details",

View File

@ -13,14 +13,13 @@
"fieldtype": "Data",
"in_list_view": 1,
"label": "Key",
"reqd": 1,
"unique": 1
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-09-03 15:41:09.997576",
"modified": "2021-09-04 17:49:33.858070",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange Settings Result",