From 53259fb91fc92ee9ff102e2665c57d2483459982 Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Thu, 23 Feb 2017 13:26:31 +0530 Subject: [PATCH] Change in student master should reflect in every linked doctype and child doctype --- erpnext/schools/doctype/student/student.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/erpnext/schools/doctype/student/student.py b/erpnext/schools/doctype/student/student.py index b660bb33639..7b6dd2c06db 100644 --- a/erpnext/schools/doctype/student/student.py +++ b/erpnext/schools/doctype/student/student.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe import _ +from frappe.desk.form.linked_with import get_linked_doctypes class Student(Document): def validate(self): @@ -15,6 +16,22 @@ class Student(Document): self.check_unique() self.update_applicant_status() + if frappe.get_value("Student", self.name, "title") != self.title: + linked_doctypes = get_linked_doctypes("Student") + print linked_doctypes + for d in linked_doctypes: + print d,linked_doctypes[d] + if "child_doctype" not in linked_doctypes[d].keys() and "student_name" in [f.fieldname for f in frappe.get_meta(d).fields]: + print "in doctype" + frappe.db.sql("""UPDATE `tab{0}` set student_name = %s where {1} = %s""" + .format(d, linked_doctypes[d]["fieldname"]),(self.title, self.name)) + + elif "child_doctype" in linked_doctypes[d].keys() and "student_name" in \ + [f.fieldname for f in frappe.get_meta(linked_doctypes[d]["child_doctype"]).fields]: + print "in child doctypes" + frappe.db.sql("""UPDATE `tab{0}` set student_name = %s where {1} = %s""" + .format(linked_doctypes[d]["child_doctype"], linked_doctypes[d]["fieldname"]),(self.title, self.name)) + def check_unique(self): """Validates if the Student Applicant is Unique""" student = frappe.db.sql("select name from `tabStudent` where student_applicant=%s and name!=%s", (self.student_applicant, self.name))