fix: consider based on DOJ config while calculating leaves for passed months
This commit is contained in:
parent
7326d57966
commit
89fa0bb73f
@ -119,14 +119,15 @@ class LeavePolicyAssignment(Document):
|
|||||||
from_date_year = get_datetime(from_date).year
|
from_date_year = get_datetime(from_date).year
|
||||||
|
|
||||||
months_passed = 0
|
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 = 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:
|
elif current_year > from_date_year:
|
||||||
months_passed = (12 - from_date_month) + current_month
|
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:
|
if months_passed > 0:
|
||||||
monthly_earned_leave = get_monthly_earned_leave(new_leaves_allocated,
|
monthly_earned_leave = get_monthly_earned_leave(new_leaves_allocated,
|
||||||
@ -138,13 +139,20 @@ class LeavePolicyAssignment(Document):
|
|||||||
return new_leaves_allocated
|
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()
|
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 based_on_doj:
|
||||||
if last_day_of_month == date:
|
# if leave type allocation is based on DOJ,
|
||||||
months_passed += 1
|
# 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
|
return months_passed
|
||||||
|
|
||||||
@ -183,7 +191,7 @@ def create_assignment_for_multiple_employees(employees, data):
|
|||||||
def get_leave_type_details():
|
def get_leave_type_details():
|
||||||
leave_type_details = frappe._dict()
|
leave_type_details = frappe._dict()
|
||||||
leave_types = frappe.get_all("Leave Type",
|
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"])
|
"is_carry_forward", "expire_carry_forwarded_leaves_after_days", "earned_leave_frequency", "rounding"])
|
||||||
for d in leave_types:
|
for d in leave_types:
|
||||||
leave_type_details.setdefault(d.name, d)
|
leave_type_details.setdefault(d.name, d)
|
||||||
|
Loading…
Reference in New Issue
Block a user