Improved Leave Application / Approver feature
diff --git a/erpnext/hr/doctype/employee/employee.js b/erpnext/hr/doctype/employee/employee.js
old mode 100644
new mode 100755
index 55bc7aa..0fedfd6
--- a/erpnext/hr/doctype/employee/employee.js
+++ b/erpnext/hr/doctype/employee/employee.js
@@ -11,9 +11,12 @@
},
onload: function() {
- this.frm.set_query("leave_approver", "leave_approvers", function() {
+ this.frm.set_query("leave_approver", "leave_approvers", function(doc) {
return {
- filters: [["UserRole", "role", "=", "Leave Approver"]]
+ query:"erpnext.hr.doctype.employee_leave_approver.employee_leave_approver.get_approvers",
+ filters:{
+ user: doc.user_id
+ }
}
});
},
diff --git a/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py b/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
old mode 100644
new mode 100755
index 4d0178f..d6a1a97
--- a/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
+++ b/erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
@@ -9,4 +9,11 @@
from frappe.model.document import Document
class EmployeeLeaveApprover(Document):
- pass
\ No newline at end of file
+ pass
+
+def get_approvers(doctype, txt, searchfield, start, page_len, filters):
+ return frappe.db.sql("""select user.name, user.first_name, user.last_name from
+ tabUser user, tabUserRole user_role where
+ user.name != %s
+ and user_role.role = "Leave Approver"
+ and user_role.parent = user.name""", filters.get("user"))
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 9d44017..79c6d95 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -31,7 +31,9 @@
},
leave_approver: function(frm) {
- frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
+ if(frm.doc.leave_approver){
+ frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
+ }
},
employee: function(frm) {
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 950400d..e407453 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -247,12 +247,23 @@
if not filters.get("employee"):
frappe.throw(_("Please select Employee Record first."))
- return frappe.db.sql("""select user.name, user.first_name, user.last_name from
+ employee_user = frappe.get_value("Employee", filters.get("employee"), "user_id")
+
+ approvers_list = frappe.db.sql("""select user.name, user.first_name, user.last_name from
tabUser user, `tabEmployee Leave Approver` approver where
approver.parent = %s
and user.name like %s
and approver.leave_approver=user.name""", (filters.get("employee"), "%" + txt + "%"))
+ if not approvers_list:
+ approvers_list = frappe.db.sql("""select user.name, user.first_name, user.last_name from
+ tabUser user, tabUserRole user_role where
+ user_role.role = "Leave Approver"
+ and user_role.parent = user.name
+ and user.name != %s
+ """, employee_user)
+ return approvers_list
+
@frappe.whitelist()
def get_number_of_leave_days(employee, leave_type, from_date, to_date, half_day=None):
if half_day: