From 351f4d53a05d2513fc7b389590b2f9d6d4906058 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Wed, 5 Jun 2019 21:22:07 +0530 Subject: [PATCH] feat: add employee filter to employee leave balance --- .../hr/doctype/leave_allocation/leave_allocation.js | 2 +- .../hr/doctype/leave_application/leave_application.js | 10 ++++++++++ .../leave_application/test_leave_application.py | 2 +- .../doctype/leave_ledger_entry/leave_ledger_entry.json | 9 ++++++++- .../employee_leave_balance/employee_leave_balance.js | 6 ++++++ .../employee_leave_balance/employee_leave_balance.py | 7 ++++--- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js index 50dbaadec7..005f45a657 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js @@ -29,7 +29,7 @@ frappe.ui.form.on("Leave Allocation", { }); // opens leave balance report for employee - frm.add_custom_button(__('Check Leave Balance'), function() { + frm.add_custom_button(__('Leave Balance'), function() { frappe.route_options = { employee: frm.doc.employee, }; diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js index 11146abce2..cb1042c5ef 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.js +++ b/erpnext/hr/doctype/leave_application/leave_application.js @@ -86,6 +86,16 @@ frappe.ui.form.on("Leave Application", { frm.set_value('employee', perm['Employee'].map(perm_doc => perm_doc.doc)[0]); } } + + if (frm.doc.docstatus === 1) { + frm.add_custom_button(__('Leave Balance'), function() { + frappe.route_options = { + employee: frm.doc.employee, + group_by: "" + }; + frappe.set_route("query-report", "Employee Leave Balance"); + }); + } }, employee: function(frm) { diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 899ce2ae8d..54216ee3c7 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -50,7 +50,7 @@ _test_records = [ class TestLeaveApplication(unittest.TestCase): def setUp(self): for dt in ["Leave Application", "Leave Allocation", "Salary Slip", "Leave Ledger Entry"]: - frappe.db.sql("DELETE FROM `tab%s`" % dt) + frappe.db.sql("DELETE FROM `tab%s`" % dt) #nosec @classmethod def setUpClass(cls): diff --git a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json index 20b64f81aa..4234fc4b40 100644 --- a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json +++ b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json @@ -14,6 +14,7 @@ "to_date", "is_carry_forward", "is_expired", + "is_lwp", "amended_from" ], "fields": [ @@ -90,11 +91,17 @@ { "fieldname": "column_break_7", "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "is_lwp", + "fieldtype": "Check", + "label": "Is Leave Without Pay" } ], "in_create": 1, "is_submittable": 1, - "modified": "2019-05-30 14:45:16.577534", + "modified": "2019-06-05 12:56:04.980160", "modified_by": "Administrator", "module": "HR", "name": "Leave Ledger Entry", diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js index 68302f6ee4..05728a297b 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js @@ -30,6 +30,12 @@ frappe.query_reports["Employee Leave Balance"] = { "label": __("Department"), "fieldtype": "Link", "options": "Department", + }, + { + "fieldname":"employee", + "label": __("Employee"), + "fieldtype": "Link", + "options": "Employee", } ] } diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py index e65220ae25..48e9bf5e5d 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py @@ -37,9 +37,10 @@ def get_conditions(filters): "company": filters.company, } if filters.get("department"): - conditions.update({ - "department": filters.get("department") - }) + conditions.update({"department": filters.get("department")}) + if filters.get("employee"): + conditions.update({"employee": filters.get("employee")}) + return conditions def get_data(filters, leave_types):