diff --git a/frappe/geo/doctype/currency/currency.js b/frappe/geo/doctype/currency/currency.js index af2d6ebc4e..1bc9865999 100644 --- a/frappe/geo/doctype/currency/currency.js +++ b/frappe/geo/doctype/currency/currency.js @@ -7,5 +7,10 @@ frappe.ui.form.on('Currency', { if(!frm.doc.enabled) { frm.set_intro(__("This Currency is disabled. Enable to use in transactions")); } + }, + + after_save(frm) { + if (frm.doc.enabled) + locals[':Currency'][frm.doc.name] = Object.assign(frm.doc, { doctype: ':Currency' }); } }); diff --git a/frappe/public/js/frappe/form/controls/currency.js b/frappe/public/js/frappe/form/controls/currency.js index 141eae1e8e..5285d38b38 100644 --- a/frappe/public/js/frappe/form/controls/currency.js +++ b/frappe/public/js/frappe/form/controls/currency.js @@ -1,12 +1,16 @@ frappe.ui.form.ControlCurrency = frappe.ui.form.ControlFloat.extend({ eval_expression: function(value) { - if (typeof value ==='string' - && value.match(/^[0-9+-/* ]+$/) - // paresFloat('1,44,000') returns 1.0 - // 1,44,000 are being passed when we paste rows from excel sheet to a table - && value.includes(',')) { - return value.replace(",", ""); + if (typeof value ==='string' && value.match(/^[0-9+-/* ]+$/)) { + // Removes seperator + value = strip_number_groups(value, this.get_number_format()); + + try { + return eval(value); + } catch (e) { + return value; + } } + // If not string return value; }, diff --git a/frappe/public/js/frappe/form/controls/float.js b/frappe/public/js/frappe/form/controls/float.js index 6ebaaa4075..71a0257597 100644 --- a/frappe/public/js/frappe/form/controls/float.js +++ b/frappe/public/js/frappe/form/controls/float.js @@ -1,7 +1,9 @@ frappe.ui.form.ControlFloat = frappe.ui.form.ControlInt.extend({ parse: function(value) { value = this.eval_expression(value); - return isNaN(parseFloat(value)) ? null : flt(value, this.get_precision()); + // For #'###.## number format, if we enter 45'00 then it gets parsed as 45.00 + // becoz number format isn't provided to flt() + return isNaN(parseFloat(value)) ? null : flt(value, this.get_precision(), this.get_number_format()); }, format_for_input: function(value) { diff --git a/frappe/public/js/frappe/utils/number_format.js b/frappe/public/js/frappe/utils/number_format.js index 57022b22c5..b8a18610bd 100644 --- a/frappe/public/js/frappe/utils/number_format.js +++ b/frappe/public/js/frappe/utils/number_format.js @@ -144,7 +144,10 @@ function get_currency_symbol(currency) { } function get_number_format(currency) { - return (frappe.boot && frappe.boot.sysdefaults && frappe.boot.sysdefaults.number_format) || "#,###.##"; + let format = null; + if (currency) format = frappe.model.get_value(":Currency", currency, "number_format"); + + return format || (frappe.boot && frappe.boot.sysdefaults && frappe.boot.sysdefaults.number_format) || "#,###.##"; } function get_number_format_info(format) {