fix: Quality Procedure Fixes

- Dont prompt error message if parent is the same in child
- filter child procedure field
- Disable New button in tree view
- Editable grid for Quality Procedure Proces table.
diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js
index ded3a51..357bd65 100644
--- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js
+++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js
@@ -2,4 +2,13 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Quality Procedure', {
+	refresh: function(frm) {
+		frm.set_query("procedure","processes", (frm) =>{
+			return {
+				filters: {
+					name: ["not in", [frm.parent_quality_procedure, frm.name]]
+				}
+			}
+		})
+	}
 });
\ No newline at end of file
diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.json b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.json
index 6df116c..b3c0d94 100644
--- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.json
+++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.json
@@ -1,5 +1,6 @@
 {
  "actions": [],
+ "allow_rename": 1,
  "autoname": "format:PRC-{quality_procedure_name}",
  "creation": "2018-10-06 00:06:29.756804",
  "doctype": "DocType",
@@ -72,7 +73,7 @@
  ],
  "is_tree": 1,
  "links": [],
- "modified": "2020-03-18 18:09:29.371627",
+ "modified": "2020-06-17 17:25:03.434953",
  "modified_by": "Administrator",
  "module": "Quality Management",
  "name": "Quality Procedure",
diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.py b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.py
index 44405c1..ea544f6 100644
--- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.py
+++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.py
@@ -10,13 +10,8 @@
 class QualityProcedure(NestedSet):
 	nsm_parent_field = 'parent_quality_procedure'
 
-	def on_save(self):
-		for process in self.processes:
-			if process.procedure:
-				doc = frappe.get_doc("Quality Procedure", process.procedure)
-				if doc.parent_quality_procedure:
-					frappe.throw(_("{0} already has a Parent Procedure {1}.").format(process.procedure, doc.parent_quality_procedure))
-				self.is_group = 1
+	def before_save(self):
+		self.check_for_incorrect_child()
 
 	def on_update(self):
 		self.set_parent()
@@ -48,11 +43,23 @@
 
 	def set_parent(self):
 		for process in self.processes:
-			if process.procedure:
+			# Set parent for only those children who don't have a parent
+			parent_quality_procedure = frappe.db.get_value("Quality Procedure", process.procedure, "parent_quality_procedure")
+			if not parent_quality_procedure and process.procedure:
 				doc = frappe.get_doc("Quality Procedure", process.procedure)
 				doc.parent_quality_procedure = self.name
 				doc.save(ignore_permissions=True)
 
+	def check_for_incorrect_child(self):
+		for process in self.processes:
+			if process.procedure:
+				# Check if any child process belongs to another parent.
+				parent_quality_procedure = frappe.db.get_value("Quality Procedure", process.procedure, "parent_quality_procedure")
+				if parent_quality_procedure and parent_quality_procedure != self.name:
+					frappe.throw(_("{0} already has a Parent Procedure {1}.".format(frappe.bold(process.procedure), frappe.bold(parent_quality_procedure))),
+						title=_("Invalid Child Procedure"))
+				self.is_group = 1
+
 @frappe.whitelist()
 def get_children(doctype, parent=None, parent_quality_procedure=None, is_root=False):
 	if parent is None or parent == "All Quality Procedures":
diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js b/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js
index 6df6f65..ef48ab6 100644
--- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js
+++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js
@@ -16,6 +16,7 @@
 		},
 	],
 	breadcrumb: "Setup",
+	disable_add_node: true,
 	root_label: "All Quality Procedures",
 	get_tree_root: false,
 	menu_items: [
diff --git a/erpnext/quality_management/doctype/quality_procedure_process/quality_procedure_process.json b/erpnext/quality_management/doctype/quality_procedure_process/quality_procedure_process.json
index 0a67fa5..3925dbb 100644
--- a/erpnext/quality_management/doctype/quality_procedure_process/quality_procedure_process.json
+++ b/erpnext/quality_management/doctype/quality_procedure_process/quality_procedure_process.json
@@ -1,6 +1,8 @@
 {
+ "actions": [],
  "creation": "2019-05-26 00:10:00.248885",
  "doctype": "DocType",
+ "editable_grid": 1,
  "engine": "InnoDB",
  "field_order": [
   "process_description",
@@ -23,7 +25,8 @@
   }
  ],
  "istable": 1,
- "modified": "2019-05-26 22:05:49.007189",
+ "links": [],
+ "modified": "2020-06-17 15:44:38.937915",
  "modified_by": "Administrator",
  "module": "Quality Management",
  "name": "Quality Procedure Process",