Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate leaves for months passed even when policy assignment is based on custom range #1697

Merged
merged 8 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,9 @@ def get_new_leaves(self, annual_allocation, leave_details, date_of_joining):
new_leaves_allocated = 0

elif leave_details.is_earned_leave:
if not self.assignment_based_on:
new_leaves_allocated = 0
else:
# get leaves for past months if assignment is based on Leave Period / Joining Date
new_leaves_allocated = self.get_leaves_for_passed_months(
annual_allocation, leave_details, date_of_joining
)
new_leaves_allocated = self.get_leaves_for_passed_months(
annual_allocation, leave_details, date_of_joining
)

else:
# calculate pro-rated leaves for other leave types
Expand Down Expand Up @@ -213,7 +209,7 @@ def _calculate_leaves_for_passed_months(consider_current_month):

period_end_date = _get_pro_rata_period_end_date(consider_current_month)

if self.effective_from < date_of_joining <= period_end_date:
if getdate(self.effective_from) <= date_of_joining <= period_end_date:
# if the employee joined within the allocation period in some previous month,
# calculate pro-rated leave for that month
# and normal monthly earned leave for remaining passed months
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_months, get_first_day, getdate
from frappe.utils import add_months, get_first_day, get_year_ending, getdate

from hrms.hr.doctype.leave_application.test_leave_application import get_employee, get_leave_period
from hrms.hr.doctype.leave_policy.test_leave_policy import create_leave_policy
Expand Down Expand Up @@ -117,5 +117,49 @@ def test_pro_rated_leave_allocation(self):
# pro-rated leave allocation for 9 months
self.assertEqual(allocation, 9)

def test_pro_rated_leave_allocation_for_custom_date_range(self):
leave_type = frappe.get_doc(
{
"doctype": "Leave Type",
"leave_type_name": "_Test Leave Type_",
"include_holiday": 1,
"is_earned_leave": 1,
"allocate_on_day": "First Day",
}
).submit()

leave_policy = frappe.get_doc(
{
"doctype": "Leave Policy",
"title": "Test Leave Policy",
"leave_policy_details": [
{
"leave_type": leave_type.name,
"annual_allocation": 12,
}
],
}
).submit()

today_date = getdate()

leave_policy_assignment = frappe.new_doc("Leave Policy Assignment")
leave_policy_assignment.employee = self.employee
leave_policy_assignment.leave_policy = leave_policy.name
leave_policy_assignment.effective_from = getdate(get_first_day(today_date))
leave_policy_assignment.effective_to = getdate(get_year_ending(today_date))
leave_policy_assignment.submit()

new_leaves_allocated = frappe.db.get_value(
"Leave Allocation",
{
"employee": leave_policy_assignment.employee,
"leave_policy_assignment": leave_policy_assignment.name,
},
"new_leaves_allocated",
)

self.assertGreater(new_leaves_allocated, 0)

def tearDown(self):
frappe.db.set_value("Employee", self.employee.name, "date_of_joining", self.original_doj)
Loading