brotherton-erpnext/erpnext/patches/v7_0/make_guardian.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.2 KiB
Python
Raw Normal View History

2016-07-21 19:47:39 +00:00
from __future__ import unicode_literals
import frappe
def execute():
2016-08-16 13:01:09 +00:00
if frappe.db.exists("DocType", "Student"):
student_table_cols = frappe.db.get_table_columns("Student")
if "father_name" in student_table_cols:
# 'Schools' module changed to the 'Education'
# frappe.reload_doc("schools", "doctype", "student")
# frappe.reload_doc("schools", "doctype", "guardian")
# frappe.reload_doc("schools", "doctype", "guardian_interest")
frappe.reload_doc("education", "doctype", "student")
frappe.reload_doc("education", "doctype", "guardian")
frappe.reload_doc("education", "doctype", "guardian_interest")
2016-08-16 13:01:09 +00:00
frappe.reload_doc("hr", "doctype", "interest")
fields = ["name", "father_name", "mother_name"]
if "father_email_id" in student_table_cols:
fields += ["father_email_id", "mother_email_id"]
2016-08-16 13:01:09 +00:00
students = frappe.get_all("Student", fields)
for stud in students:
if stud.father_name:
make_guardian(stud.father_name, stud.name, stud.father_email_id)
if stud.mother_name:
make_guardian(stud.mother_name, stud.name, stud.mother_email_id)
2016-07-21 19:47:39 +00:00
def make_guardian(name, student, email=None):
frappe.get_doc({
'doctype': 'Guardian',
'guardian_name': name,
'email': email,
'student': student
}).insert()