From 06fd51bf696a0344c6ebc8df77f2ebe307e93871 Mon Sep 17 00:00:00 2001 From: Zlash65 Date: Mon, 14 May 2018 17:16:27 +0530 Subject: [PATCH] patch fix for instructor --- ...ate_department_records_for_each_company.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/erpnext/patches/v11_0/create_department_records_for_each_company.py b/erpnext/patches/v11_0/create_department_records_for_each_company.py index 514c7090716..94071857d79 100644 --- a/erpnext/patches/v11_0/create_department_records_for_each_company.py +++ b/erpnext/patches/v11_0/create_department_records_for_each_company.py @@ -32,6 +32,8 @@ def execute(): for d in doctypes: update_records(d, comp_dict) + update_instructors(comp_dict) + def update_records(doctype, comp_dict): when_then = [] for company in comp_dict: @@ -48,4 +50,24 @@ def update_records(doctype, comp_dict): `tab%s` set department = CASE %s END - """%(doctype, " ".join(when_then)), debug=1) + """%(doctype, " ".join(when_then))) + +def update_instructors(comp_dict): + when_then = [] + emp_details = frappe.get_all("Employee", fields=["name", "company"]) + + for employee in emp_details: + records = comp_dict[employee.company] + + for department in records: + when_then.append(''' + WHEN employee = "%s" and department = "%s" + THEN "%s" + '''%(employee.name, department, records[department])) + + frappe.db.sql(""" + update + `tabInstructor` + set + department = CASE %s END + """%(" ".join(when_then)))