I tested Leave policy assignment based on joinong date for an Employee who’s joining date was more then 3 years ago (40 months), but months_passed calculated were only 5 months. Because of this line:
from_date = getdate(date_of_joining)
months_passed = 0
based_on_doj = leave_type_details.get(leave_type).based_on_date_of_joining
if current_date.year == from_date.year and current_date.month >= from_date.month:
months_passed = current_date.month - from_date.month
months_passed = add_current_month_if_applicable(months_passed, date_of_joining, based_on_doj)
elif current_date.year > from_date.year:
months_passed = (12 - from_date.month) + current_date.month
months_passed = add_current_month_if_applicable(months_passed, date_of_joining, based_on_doj)
if months_passed > 0:
monthly_earned_leave = get_monthly_earned_leave(new_leaves_allocated,
leave_type_details.get(leave_type).earned_leave_frequency, leave_type_details.get(leave_type).rounding)
new_leaves_allocated = monthly_earned_leave * months_passed
else:
new_leaves_allocated = 0
return new_leaves_allocated
This simply should be difference months between from_date (joining_date) and to_date (effective_to)
I tested in ERPNext v13.21.1 but this bug is also present in version-14-beta, and i assume its also in v13.21.1 prior versions too.
Github Issue:
https://github.com/frappe/erpnext/issues/30679