Merge pull request #22219 from Anurag810/quality_procedure_fix
fix: Child is shown in Parent process if added from tree view
This commit is contained in:
commit
b5af614824
@ -2,4 +2,13 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Quality Procedure', {
|
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]]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
|
"allow_rename": 1,
|
||||||
"autoname": "format:PRC-{quality_procedure_name}",
|
"autoname": "format:PRC-{quality_procedure_name}",
|
||||||
"creation": "2018-10-06 00:06:29.756804",
|
"creation": "2018-10-06 00:06:29.756804",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
@ -72,7 +73,7 @@
|
|||||||
],
|
],
|
||||||
"is_tree": 1,
|
"is_tree": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-03-18 18:09:29.371627",
|
"modified": "2020-06-17 17:25:03.434953",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Quality Management",
|
"module": "Quality Management",
|
||||||
"name": "Quality Procedure",
|
"name": "Quality Procedure",
|
||||||
|
@ -11,18 +11,18 @@ class QualityProcedure(NestedSet):
|
|||||||
nsm_parent_field = 'parent_quality_procedure'
|
nsm_parent_field = 'parent_quality_procedure'
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
for process in self.processes:
|
self.check_for_incorrect_child()
|
||||||
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 on_update(self):
|
def on_update(self):
|
||||||
self.set_parent()
|
self.set_parent()
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
self.set_parent()
|
self.set_parent()
|
||||||
|
#if Child is Added through Tree View.
|
||||||
|
if self.parent_quality_procedure:
|
||||||
|
parent_quality_procedure = frappe.get_doc("Quality Procedure", self.parent_quality_procedure)
|
||||||
|
parent_quality_procedure.append("processes", {"procedure": self.name})
|
||||||
|
parent_quality_procedure.save()
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
if self.parent_quality_procedure:
|
if self.parent_quality_procedure:
|
||||||
@ -42,11 +42,21 @@ class QualityProcedure(NestedSet):
|
|||||||
doc.save(ignore_permissions=True)
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
def set_parent(self):
|
def set_parent(self):
|
||||||
|
for process in self.processes:
|
||||||
|
# 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:
|
||||||
|
frappe.db.set_value(self.doctype, process.procedure, "parent_quality_procedure", self.name)
|
||||||
|
|
||||||
|
def check_for_incorrect_child(self):
|
||||||
for process in self.processes:
|
for process in self.processes:
|
||||||
if process.procedure:
|
if process.procedure:
|
||||||
doc = frappe.get_doc("Quality Procedure", process.procedure)
|
# Check if any child process belongs to another parent.
|
||||||
doc.parent_quality_procedure = self.name
|
parent_quality_procedure = frappe.db.get_value("Quality Procedure", process.procedure, "parent_quality_procedure")
|
||||||
doc.save(ignore_permissions=True)
|
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()
|
@frappe.whitelist()
|
||||||
def get_children(doctype, parent=None, parent_quality_procedure=None, is_root=False):
|
def get_children(doctype, parent=None, parent_quality_procedure=None, is_root=False):
|
||||||
|
@ -16,6 +16,7 @@ frappe.treeview_settings["Quality Procedure"] = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
breadcrumb: "Setup",
|
breadcrumb: "Setup",
|
||||||
|
disable_add_node: true,
|
||||||
root_label: "All Quality Procedures",
|
root_label: "All Quality Procedures",
|
||||||
get_tree_root: false,
|
get_tree_root: false,
|
||||||
menu_items: [
|
menu_items: [
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"actions": [],
|
||||||
"creation": "2019-05-26 00:10:00.248885",
|
"creation": "2019-05-26 00:10:00.248885",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"process_description",
|
"process_description",
|
||||||
@ -23,7 +25,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2019-05-26 22:05:49.007189",
|
"links": [],
|
||||||
|
"modified": "2020-06-17 15:44:38.937915",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Quality Management",
|
"module": "Quality Management",
|
||||||
"name": "Quality Procedure Process",
|
"name": "Quality Procedure Process",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user