fix: calculate pending leaves (#19411)
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 97de40f..b73028e 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_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 '''