Improved Leave Application / Approver feature
This commit is contained in:
parent
6221117069
commit
33cc081c3b
7
erpnext/hr/doctype/employee/employee.js
Normal file → Executable file
7
erpnext/hr/doctype/employee/employee.js
Normal file → Executable file
@ -11,9 +11,12 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onload: function() {
|
onload: function() {
|
||||||
this.frm.set_query("leave_approver", "leave_approvers", function() {
|
this.frm.set_query("leave_approver", "leave_approvers", function(doc) {
|
||||||
return {
|
return {
|
||||||
filters: [["UserRole", "role", "=", "Leave Approver"]]
|
query:"erpnext.hr.doctype.employee_leave_approver.employee_leave_approver.get_approvers",
|
||||||
|
filters:{
|
||||||
|
user: doc.user_id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
9
erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
Normal file → Executable file
9
erpnext/hr/doctype/employee_leave_approver/employee_leave_approver.py
Normal file → Executable file
@ -9,4 +9,11 @@ import frappe
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class EmployeeLeaveApprover(Document):
|
class EmployeeLeaveApprover(Document):
|
||||||
pass
|
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"))
|
@ -31,7 +31,9 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
leave_approver: function(frm) {
|
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) {
|
employee: function(frm) {
|
||||||
|
@ -247,12 +247,23 @@ def get_approvers(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
if not filters.get("employee"):
|
if not filters.get("employee"):
|
||||||
frappe.throw(_("Please select Employee Record first."))
|
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
|
tabUser user, `tabEmployee Leave Approver` approver where
|
||||||
approver.parent = %s
|
approver.parent = %s
|
||||||
and user.name like %s
|
and user.name like %s
|
||||||
and approver.leave_approver=user.name""", (filters.get("employee"), "%" + txt + "%"))
|
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()
|
@frappe.whitelist()
|
||||||
def get_number_of_leave_days(employee, leave_type, from_date, to_date, half_day=None):
|
def get_number_of_leave_days(employee, leave_type, from_date, to_date, half_day=None):
|
||||||
if half_day:
|
if half_day:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user