From d75ac136d7a8a66df2965bb9bb33b3134eb4cae5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:32:35 +0530 Subject: [PATCH] fix: typerror on tree doctypes - Item Group, Customer Group, Supplier Group and Territory (backport #38870) (#38871) fix: typerror on tree doctypes - Item Group, Customer Group, Supplier Group and Territory (#38870) * refactor: typerror on set_root_readonly * refactor: remove 'cur_frm' usage in supplier_group * refactor: remove 'cur_frm' usage in territory.js * refactor: remove 'cur_frm' from sales_person.js (cherry picked from commit 6d5bdc6c68dfda915972f3747de752b8fad7cdb5) Co-authored-by: ruthra kumar --- .../doctype/customer_group/customer_group.js | 29 +++++++++---------- .../doctype/sales_person/sales_person.js | 23 +++++++-------- .../doctype/supplier_group/supplier_group.js | 27 ++++++++--------- erpnext/setup/doctype/territory/territory.js | 27 +++++++++-------- 4 files changed, 48 insertions(+), 58 deletions(-) diff --git a/erpnext/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js index 3c81b0283c..e3528189dc 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.js +++ b/erpnext/setup/doctype/customer_group/customer_group.js @@ -1,21 +1,6 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - cur_frm.cscript.set_root_readonly(doc); -} - -cur_frm.cscript.set_root_readonly = function(doc) { - // read-only for root customer group - if(!doc.parent_customer_group && !doc.__islocal) { - cur_frm.set_read_only(); - cur_frm.set_intro(__("This is a root customer group and cannot be edited.")); - } else { - cur_frm.set_intro(null); - } -} - frappe.ui.form.on("Customer Group", { setup: function(frm){ frm.set_query('parent_customer_group', function (doc) { @@ -48,5 +33,17 @@ frappe.ui.form.on("Customer Group", { } } }); - } + }, + refresh: function(frm) { + frm.trigger("set_root_readonly"); + }, + set_root_readonly: function(frm) { + // read-only for root customer group + if(!frm.doc.parent_customer_group && !frm.doc.__islocal) { + frm.set_read_only(); + frm.set_intro(__("This is a root customer group and cannot be edited.")); + } else { + frm.set_intro(null); + } + }, }); diff --git a/erpnext/setup/doctype/sales_person/sales_person.js b/erpnext/setup/doctype/sales_person/sales_person.js index d86a8f3d98..f0d9aa87bc 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.js +++ b/erpnext/setup/doctype/sales_person/sales_person.js @@ -11,6 +11,7 @@ frappe.ui.form.on('Sales Person', { frm.dashboard.add_indicator(__('Total Contribution Amount Against Invoices: {0}', [format_currency(info.allocated_amount_against_invoice, info.currency)]), 'blue'); } + frm.trigger("set_root_readonly"); }, setup: function(frm) { @@ -27,22 +28,18 @@ frappe.ui.form.on('Sales Person', { 'Sales Order': () => frappe.new_doc("Sales Order") .then(() => frm.add_child("sales_team", {"sales_person": frm.doc.name})) } + }, + set_root_readonly: function(frm) { + // read-only for root + if(!frm.doc.parent_sales_person && !frm.doc.__islocal) { + frm.set_read_only(); + frm.set_intro(__("This is a root sales person and cannot be edited.")); + } else { + frm.set_intro(null); + } } }); -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - cur_frm.cscript.set_root_readonly(doc); -} - -cur_frm.cscript.set_root_readonly = function(doc) { - // read-only for root - if(!doc.parent_sales_person && !doc.__islocal) { - cur_frm.set_read_only(); - cur_frm.set_intro(__("This is a root sales person and cannot be edited.")); - } else { - cur_frm.set_intro(null); - } -} //get query select sales person cur_frm.fields_dict['parent_sales_person'].get_query = function(doc, cdt, cdn) { diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.js b/erpnext/setup/doctype/supplier_group/supplier_group.js index 33629297ff..c697a99cb4 100644 --- a/erpnext/setup/doctype/supplier_group/supplier_group.js +++ b/erpnext/setup/doctype/supplier_group/supplier_group.js @@ -1,21 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -cur_frm.cscript.refresh = function(doc) { - cur_frm.set_intro(doc.__islocal ? "" : __("There is nothing to edit.")); - cur_frm.cscript.set_root_readonly(doc); -}; - -cur_frm.cscript.set_root_readonly = function(doc) { - // read-only for root customer group - if(!doc.parent_supplier_group && !doc.__islocal) { - cur_frm.set_read_only(); - cur_frm.set_intro(__("This is a root supplier group and cannot be edited.")); - } else { - cur_frm.set_intro(null); - } -}; - frappe.ui.form.on("Supplier Group", { setup: function(frm){ frm.set_query('parent_supplier_group', function (doc) { @@ -48,5 +33,17 @@ frappe.ui.form.on("Supplier Group", { } } }); + }, + refresh: function(frm) { + frm.set_intro(frm.doc.__islocal ? "" : __("There is nothing to edit.")); + frm.trigger("set_root_readonly"); + }, + set_root_readonly: function(frm) { + if(!frm.doc.parent_supplier_group && !frm.doc.__islocal) { + frm.trigger("set_read_only"); + frm.set_intro(__("This is a root supplier group and cannot be edited.")); + } else { + frm.set_intro(null); + } } }); diff --git a/erpnext/setup/doctype/territory/territory.js b/erpnext/setup/doctype/territory/territory.js index 3caf814c90..e11d20b7bf 100644 --- a/erpnext/setup/doctype/territory/territory.js +++ b/erpnext/setup/doctype/territory/territory.js @@ -11,23 +11,22 @@ frappe.ui.form.on("Territory", { } } }; + }, + refresh: function(frm) { + frm.trigger("set_root_readonly"); + }, + set_root_readonly: function(frm) { + // read-only for root territory + if(!frm.doc.parent_territory && !frm.doc.__islocal) { + frm.set_read_only(); + frm.set_intro(__("This is a root territory and cannot be edited.")); + } else { + frm.set_intro(null); + } } + }); -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - cur_frm.cscript.set_root_readonly(doc); -} - -cur_frm.cscript.set_root_readonly = function(doc) { - // read-only for root territory - if(!doc.parent_territory && !doc.__islocal) { - cur_frm.set_read_only(); - cur_frm.set_intro(__("This is a root territory and cannot be edited.")); - } else { - cur_frm.set_intro(null); - } -} - //get query select territory cur_frm.fields_dict['parent_territory'].get_query = function(doc,cdt,cdn) { return{