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:
rohitwaghchaure 2020-06-18 15:51:00 +05:30 committed by GitHub
commit b5af614824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 11 deletions

View File

@ -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]]
}
};
});
}
});

View File

@ -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",

View File

@ -11,18 +11,18 @@ class QualityProcedure(NestedSet):
nsm_parent_field = 'parent_quality_procedure'
def before_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
self.check_for_incorrect_child()
def on_update(self):
self.set_parent()
def after_insert(self):
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):
if self.parent_quality_procedure:
@ -42,11 +42,21 @@ class QualityProcedure(NestedSet):
doc.save(ignore_permissions=True)
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:
if process.procedure:
doc = frappe.get_doc("Quality Procedure", process.procedure)
doc.parent_quality_procedure = self.name
doc.save(ignore_permissions=True)
# 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):

View File

@ -16,6 +16,7 @@ frappe.treeview_settings["Quality Procedure"] = {
},
],
breadcrumb: "Setup",
disable_add_node: true,
root_label: "All Quality Procedures",
get_tree_root: false,
menu_items: [

View File

@ -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",