From 7638788c2f3f3fab80f2ef782bf843b17f428b46 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Wed, 30 Oct 2019 14:23:41 +0530 Subject: [PATCH] fix: calculate pending leaves (#19411) --- .../hr/doctype/leave_application/leave_application.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 97de40ffee..b73028e50a 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -503,14 +503,17 @@ def get_leave_allocation_records(employee, date, leave_type=None): def get_pending_leaves_for_period(employee, leave_type, from_date, to_date): ''' Returns leaves that are pending approval ''' - return frappe.db.get_value("Leave Application", + leaves = frappe.get_all("Leave Application", filters={ "employee": employee, "leave_type": leave_type, - "from_date": ("<=", from_date), - "to_date": (">=", to_date), "status": "Open" - }, fieldname=['SUM(total_leave_days)']) or flt(0) + }, + or_filters={ + "from_date": ["between", (from_date, to_date)], + "to_date": ["between", (from_date, to_date)] + }, fields=['SUM(total_leave_days) as leaves'])[0] + return leaves['leaves'] if leaves['leaves'] else 0.0 def get_remaining_leaves(allocation, leaves_taken, date, expiry): ''' Returns minimum leaves remaining after comparing with remaining days for allocation expiry '''