ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

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("""
SELECT
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?

Thanks.