From 812224e56eea77a16edcc163c2129398b313f130 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 20 May 2018 21:21:33 +0530 Subject: [PATCH] Set leave approver in the leave application --- .../leave_application/leave_application.js | 18 ++++++++++++++++++ .../leave_application/leave_application.py | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js index 06eee618cb..b3357178a2 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.js +++ b/erpnext/hr/doctype/leave_application/leave_application.js @@ -42,6 +42,7 @@ frappe.ui.form.on("Leave Application", { employee: function(frm) { frm.trigger("get_leave_balance"); + frm.trigger("set_leave_approver"); }, leave_type: function(frm) { @@ -125,4 +126,21 @@ frappe.ui.form.on("Leave Application", { }); } }, + + set_leave_approver: function(frm) { + if(frm.doc.employee) { + // server call is done to include holidays in leave days calculations + return frappe.call({ + method: 'erpnext.hr.doctype.leave_application.leave_application.get_leave_approver_data', + args: { + "employee": frm.doc.employee, + }, + callback: function(r) { + if (r && r.message) { + frm.set_value('leave_approver', r.message); + } + } + }); + } + } }); diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 4e1b54b95b..83079d415d 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -530,3 +530,8 @@ def add_holidays(events, start, end, employee, company): "title": _("Holiday") + ": " + cstr(holiday.description), "name": holiday.name }) + +@frappe.whitelist() +def get_leave_approver_data(employee): + return frappe.db.get_value("Employee Leave Approver", + {'parent': employee}, 'leave_approver')