From f13243a92eba52883aefe645d346ef4a67685958 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 6 Jun 2019 20:35:10 +0530 Subject: [PATCH] feat: fetch annual allocation based on leave policy --- .../hr/doctype/leave_allocation/leave_allocation.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js index 005f45a657..7ecd3d1c91 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js @@ -58,6 +58,7 @@ frappe.ui.form.on("Leave Allocation", { }, leave_type: function(frm) { + frm.trigger("leave_policy") frm.trigger("calculate_total_leaves_allocated"); }, @@ -75,6 +76,17 @@ frappe.ui.form.on("Leave Allocation", { flt(frm.doc.carry_forwarded_leaves) + flt(frm.doc.new_leaves_allocated)); }, + leave_policy: function(frm) { + if(frm.doc.leave_policy && frm.doc.leave_type) { + frappe.db.get_value("Leave Policy Detail", + {'parent': frm.doc.leave_policy, 'leave_type': frm.doc.leave_type}, + 'annual_allocation', (r) => { + if (!r.exc) { + frm.set_value("new_leaves_allocated", flt(r.annual_allocation)); + } + }, "Leave Policy") + } + }, calculate_total_leaves_allocated: function(frm) { if (cint(frm.doc.carry_forward) == 1 && frm.doc.leave_type && frm.doc.employee) { return frappe.call({