tree based changes
diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.js b/erpnext/setup/doctype/supplier_group/supplier_group.js
index 10e5c04..ea92726 100644
--- a/erpnext/setup/doctype/supplier_group/supplier_group.js
+++ b/erpnext/setup/doctype/supplier_group/supplier_group.js
@@ -2,7 +2,27 @@
// 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.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) {
+ 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);
+ }
+}
+
+//get query select Customer Group
+cur_frm.fields_dict['parent_supplier_group'].get_query = function(doc,cdt,cdn) {
+ return {
+ filters: {
+ 'is_group': 1
+ }
+ }
}
cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) {
diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.py b/erpnext/setup/doctype/supplier_group/supplier_group.py
index 53ab215..747560a 100644
--- a/erpnext/setup/doctype/supplier_group/supplier_group.py
+++ b/erpnext/setup/doctype/supplier_group/supplier_group.py
@@ -4,7 +4,17 @@
from __future__ import unicode_literals
import frappe
-from frappe.model.document import Document
+from frappe.utils.nestedset import NestedSet
-class SupplierGroup(Document):
- pass
+class SupplierGroup(NestedSet):
+ nsm_parent_field = 'parent_supplier_group';
+
+ def update_nsm_model(self):
+ frappe.utils.nestedset.update_nsm(self)
+
+ def on_update(self):
+ self.update_nsm_model()
+ self.validate_one_root()
+
+ def on_trash(self):
+ self.update_nsm_model()