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)))