fix: consider based on DOJ config while calculating leaves for passed months

(cherry picked from commit 89fa0bb73f)
This commit is contained in:
Rucha Mahabal
2022-02-09 11:28:14 +05:30
committed by mergify-bot
parent 2b4e532226
commit 3fea6fd9e8

View File

@@ -120,14 +120,15 @@ class LeavePolicyAssignment(Document):
from_date_year = get_datetime(from_date).year
months_passed = 0
based_on_doj = leave_type_details.get(leave_type).based_on_date_of_joining
if current_year == from_date_year and current_month > from_date_month:
if current_year == from_date_year and current_month >= from_date_month:
months_passed = current_month - from_date_month
months_passed = add_current_month_if_applicable(months_passed)
months_passed = add_current_month_if_applicable(months_passed, date_of_joining, based_on_doj)
elif current_year > from_date_year:
months_passed = (12 - from_date_month) + current_month
months_passed = add_current_month_if_applicable(months_passed)
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,
@@ -139,13 +140,20 @@ class LeavePolicyAssignment(Document):
return new_leaves_allocated
def add_current_month_if_applicable(months_passed):
def add_current_month_if_applicable(months_passed, date_of_joining, based_on_doj):
date = getdate(frappe.flags.current_date) or getdate()
last_day_of_month = get_last_day(date)
# if its the last day of the month, then that month should also be considered
if last_day_of_month == date:
months_passed += 1
if based_on_doj:
# if leave type allocation is based on DOJ,
# and the date of assignment creation is same as DOJ,
# then the month should be considered
if date == date_of_joining:
months_passed += 1
else:
last_day_of_month = get_last_day(date)
# if its the last day of the month, then that month should be considered
if last_day_of_month == date:
months_passed += 1
return months_passed
@@ -184,7 +192,7 @@ def create_assignment_for_multiple_employees(employees, data):
def get_leave_type_details():
leave_type_details = frappe._dict()
leave_types = frappe.get_all("Leave Type",
fields=["name", "is_lwp", "is_earned_leave", "is_compensatory",
fields=["name", "is_lwp", "is_earned_leave", "is_compensatory", "based_on_date_of_joining",
"is_carry_forward", "expire_carry_forwarded_leaves_after_days", "earned_leave_frequency", "rounding"])
for d in leave_types:
leave_type_details.setdefault(d.name, d)