Employee Leave Balance report is showing wrong figures

I am using version 13.7.0 and I discovered that the Employee Leave balance is showing wrong leave balance figures. I checked the employee_leave_balance.py file and found there is a bug here which it should only fetch only Leave Allocation records but it fetches all records.

I modified the following function (highlighted in bold) and the leave balance seems OK now.

def get_allocated_and_expired_leaves(from_date, to_date, employee, leave_type):
from frappe.utils import getdate
new_allocation = 0
expired_leaves = 0
records= frappe.db.sql("""
employee, leave_type, from_date, to_date, leaves, transaction_name,
transaction_type, is_carry_forward, is_expired
FROM tabLeave Ledger Entry
WHERE employee=%(employee)s AND leave_type=%(leave_type)s
AND docstatus=1
AND transaction_type = 'Leave Allocation’
AND (from_date between %(from_date)s AND %(to_date)s
OR to_date between %(from_date)s AND %(to_date)s
OR (from_date < %(from_date)s AND to_date > %(to_date)s))
“”", {
“from_date”: from_date,
“to_date”: to_date,
“employee”: employee,
“leave_type”: leave_type
}, as_dict=1)
for record in records:
if record.to_date < getdate(to_date):
expired_leaves += record.leaves
if record.from_date >= getdate(from_date):
new_allocation += record.leaves
return new_allocation, expired_leaves


Can anyone verify this and implement the fix?


Hi @gohyc
Yes, I can confirm the problem exists. Can you open a GIT merge request for the same?
The solution should work though as confirmed by @hanntd here

I have not done this before. Can you tell me how I create a GIT merge request to this?


I have created a pull request #27728 for the fix.

1 Like

This issue is now resolved in the latest v13.13

1 Like