Hi,
i have newest version on development branch and noticed in Leave Application Dashboard that scripts calculating Half Day as 1.0, not as 0.5.
My quick solution:
leave_application.py file:
Available Leaves Fix
Actual:
def get_leaves_for_period(employee, leave_type, from_date, to_date):
leave_entries = get_leave_entries(employee, leave_type, from_date, to_date)
leave_days = 0
for leave_entry in leave_entries:
inclusive_period = leave_entry.from_date >= getdate(from_date) and leave_entry.to_date <= getdate(to_date)
if inclusive_period and leave_entry.transaction_type == 'Leave Encashment':
leave_days += leave_entry.leaves
elif inclusive_period and leave_entry.transaction_type == 'Leave Allocation' \
and not skip_expiry_leaves(leave_entry, to_date):
leave_days += leave_entry.leaves
else:
if leave_entry.from_date < getdate(from_date):
leave_entry.from_date = from_date
if leave_entry.to_date > getdate(to_date):
leave_entry.to_date = to_date
leave_days += get_number_of_leave_days(employee, leave_type,
leave_entry.from_date, leave_entry.to_date) * -1
…
My fix:
def get_leaves_for_period(employee, leave_type, from_date, to_date):
leave_entries = get_leave_entries(employee, leave_type, from_date, to_date)
leave_days = 0
for leave_entry in leave_entries:
inclusive_period = leave_entry.from_date >= getdate(from_date) and leave_entry.to_date <= getdate(to_date)
if inclusive_period and leave_entry.transaction_type == 'Leave Encashment':
leave_days += leave_entry.leaves
elif inclusive_period and leave_entry.transaction_type == 'Leave Allocation' \
and not skip_expiry_leaves(leave_entry, to_date):
leave_days += leave_entry.leaves
elif inclusive_period and leave_entry.transaction_type == 'Leave Application' \
and not skip_expiry_leaves(leave_entry, to_date):
leave_days += leave_entry.leaves
else:
if leave_entry.from_date < getdate(from_date):
leave_entry.from_date = from_date
if leave_entry.to_date > getdate(to_date):
leave_entry.to_date = to_date
leave_days += get_number_of_leave_days(employee, leave_type,
leave_entry.from_date, leave_entry.to_date) * -1
Pending Leaves Fix
Actual:
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",
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)
My fix:
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",
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)
See report here https://discuss.erpnext.com/t/v12-employee-leave-balance-report-is-reporting-wrong-leave-balance-if-employee-has-taken-half-day-leave/53420
A user has tried the proposed fix and reports that it works.
I have added fixes for both the problems over here: #19323 #19411
Most helpful comment
I have added fixes for both the problems over here: #19323 #19411