2018-04-20 04:58:52 +00:00
|
|
|
import frappe
|
2018-06-13 11:41:17 +00:00
|
|
|
from frappe.model.utils.rename_field import rename_field
|
2018-04-20 04:58:52 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-04-20 04:58:52 +00:00
|
|
|
def execute():
|
2018-04-23 07:51:35 +00:00
|
|
|
frappe.reload_doc("hr", "doctype", "department_approver")
|
2018-04-20 04:58:52 +00:00
|
|
|
frappe.reload_doc("hr", "doctype", "employee")
|
|
|
|
frappe.reload_doc("hr", "doctype", "department")
|
|
|
|
|
2018-06-13 11:41:17 +00:00
|
|
|
if frappe.db.has_column("Department", "leave_approver"):
|
|
|
|
rename_field("Department", "leave_approver", "leave_approvers")
|
|
|
|
|
|
|
|
if frappe.db.has_column("Department", "expense_approver"):
|
|
|
|
rename_field("Department", "expense_approver", "expense_approvers")
|
|
|
|
|
2018-06-14 07:37:52 +00:00
|
|
|
if not frappe.db.table_exists("Employee Leave Approver"):
|
|
|
|
return
|
|
|
|
|
2018-04-20 04:58:52 +00:00
|
|
|
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,
|
|
|
|
)
|
2018-06-13 11:41:17 +00:00
|
|
|
|
2018-04-20 04:58:52 +00:00
|
|
|
for record in approvers:
|
|
|
|
if record.department:
|
2018-06-13 11:41:17 +00:00
|
|
|
department = frappe.get_doc("Department", record.department)
|
|
|
|
if not department:
|
|
|
|
return
|
|
|
|
if not len(department.leave_approvers):
|
|
|
|
department.append("leave_approvers", {"approver": record.leave_approver}).db_insert()
|