From e6712c129c9921ce250ba209f0ed42ba56e36d2c Mon Sep 17 00:00:00 2001 From: Makarand Bauskar Date: Wed, 25 Oct 2017 12:17:40 +0530 Subject: [PATCH] [hotfix] fixed Permissions Error while fetching allow_stale field value from Accounts Settings (#11182) * [hotfix] fixed Permissions Error while fetching allow_stale field value from Accounts Settings * [minor] renamed the allow_stale_rate method to stale_rate_allowed --- .../accounts/doctype/payment_entry/payment_entry.js | 12 ++---------- erpnext/public/js/controllers/transaction.js | 6 +----- erpnext/public/js/utils.js | 4 ++++ erpnext/startup/boot.py | 2 ++ 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index fc9fc973329..17ac1f70567 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -405,11 +405,7 @@ frappe.ui.form.on('Payment Entry', { } // Make read only if Accounts Settings doesn't allow stale rates - frappe.model.get_value("Accounts Settings", null, "allow_stale", - function(d){ - frm.set_df_property("source_exchange_rate", "read_only", cint(d.allow_stale) ? 0 : 1); - } - ); + frm.set_df_property("source_exchange_rate", "read_only", erpnext.stale_rate_allowed()); }, target_exchange_rate: function(frm) { @@ -430,11 +426,7 @@ frappe.ui.form.on('Payment Entry', { frm.set_paid_amount_based_on_received_amount = false; // Make read only if Accounts Settings doesn't allow stale rates - frappe.model.get_value("Accounts Settings", null, "allow_stale", - function(d){ - frm.set_df_property("target_exchange_rate", "read_only", cint(d.allow_stale) ? 0 : 1); - } - ); + frm.set_df_property("target_exchange_rate", "read_only", erpnext.stale_rate_allowed()); }, paid_amount: function(frm) { diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 5b647f80d28..41fdc6e6462 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -542,11 +542,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } // Make read only if Accounts Settings doesn't allow stale rates - frappe.model.get_value("Accounts Settings", null, "allow_stale", - function(d){ - me.set_df_property("conversion_rate", "read_only", cint(d.allow_stale) ? 0 : 1); - } - ); + this.frm.set_df_property("conversion_rate", "read_only", erpnext.stale_rate_allowed()); }, set_actual_charges_based_on_currency: function() { diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 721f216888b..efb04d1c093 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -37,6 +37,10 @@ $.extend(erpnext, { } }, + stale_rate_allowed: () => { + return cint(frappe.boot.sysdefaults.allow_stale) || 1; + }, + setup_serial_no: function() { var grid_row = cur_frm.open_grid_row(); if(!grid_row || !grid_row.grid_form.fields_dict.serial_no || diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py index 31643061091..2080224a705 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -19,6 +19,8 @@ def boot_session(bootinfo): 'territory') bootinfo.sysdefaults.customer_group = frappe.db.get_single_value('Selling Settings', 'customer_group') + bootinfo.sysdefaults.allow_stale = frappe.db.get_single_value('Accounts Settings', + 'allow_stale') or 1 bootinfo.notification_settings = frappe.get_doc("Notification Control", "Notification Control")