Problem with employee leave calculations

There is problem with leave calculation. I am using v12.10.1.

For my example, I have a brought forward annual leave from last year which is 3 days. Together with the 10 days allocated for this year. And it becomes 13 days in the leave allocation, which is OK.

The brought forward leave expired in 3 months (since I didn’t utilize it) and here is the leave balance report.

I am not sure why there is an opening leave balance of -6 here. And it it brings my leave balance to 13 - 6 - 3 (expired leave) = 4.

And when I try to apply leave.

Why is there 122 days of total allocation and 112 day of expired leaves? And I didn’t use the 3 days leave (is it the expired leaves?). And my pending leave is 10 and available leave becomes 7 (which should be 10).

The 3 day expired leaves become the used leave, and the number is deducted from my Pending leaves and my available leave becomes 7 which is wrong.

Hi gohyc,

For some reason ERPNext in that Leave Application dashboard is reporting the leaves for all employees. That’s wrong of course and hopefully there should be a fix soon.

Not sure if there is a problem with the expiring leaves too. Probably not. Please check carefully if you’ve done everything okay.

Hope this helps.

Thanks

Jay

I am quite sure the expired leave setting is done correctly. Here is the screenshot of the leave type.

The maximum carry forward is 3 and expire days is 90. I didn’t any leave and the used leave became 3 in the dashboard.

The leave balance calculation is fixed on the development branch but not on the version-12 branch. Can somebody apply the fix in version-12 branch?

As for the expiring leave calculation, after examined the code, I think here is the problem:

In the get_leaves_for_period function in leave_application.py, there is a statement to add the expired leave to the total leave taken count:

elif inclusive_period and leave_entry.transaction_type == ‘Leave Allocation’ and leave_entry.is_expired
and (do_not_skip_expired_leaves or not skip_expiry_leaves(leave_entry, to_date)):
leave_days += leave_entry.leaves

It is calling the skip_expiry_leaves function to decide whether to add the expired leaves to the leave count.

And here is the function:

def skip_expiry_leaves(leave_entry, date):
‘’’ Checks whether the expired leaves coincide with the to_date of leave balance check.
This allows backdated leave entry creation for non carry forwarded allocation ‘’’
end_date = frappe.db.get_value(“Leave Allocation”, {‘name’: leave_entry.transaction_name}, [‘to_date’])
return True if end_date == date and not leave_entry.is_carry_forward else False

And it will return False because I have a Leave Ledger Entry that is marked as expired on 30 Mar (3 months validity for a carry forwarded leave) because the end_date is not equal to date.

And I am not sure why calling skip_expiry_leaves is required when calculating the leaves used.