brotherton-erpnext/erpnext/patches/v11_0/move_leave_approvers_from_employee.py
Shreya Shah 828f5ab29e Patch fixes (#13754)
* reload doc

* remove unused code
2018-04-23 13:21:35 +05:30

19 lines
733 B
Python

import frappe
from frappe import _
def execute():
frappe.reload_doc("hr", "doctype", "department_approver")
frappe.reload_doc("hr", "doctype", "employee")
frappe.reload_doc("hr", "doctype", "department")
approvers = frappe.db.sql("""select distinct app.leave_approver, emp.department from
`tabEmployee Leave Approver` app, `tabEmployee` emp
where app.parenttype = 'Employee'
and emp.name = app.parent
""", as_dict=True)
for record in approvers:
if record.department:
frappe.db.sql("""update `tabDepartment Approver` app set app.parenttype = '{0}',
app.parent = '{1}' and parentfield = 'leave_approver' where app.leave_approver = '{2}'"""
.format(_('Department'), record.department, record.leave_approver))