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: filter out old allocation's cf leaves while fetching leave details #34723

Merged
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
3 changes: 3 additions & 0 deletions erpnext/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ def get_leave_allocation_records(employee, date, leave_type=None):
| (
(Ledger.is_carry_forward == 1)
& (Ledger.to_date.between(LeaveAllocation.from_date, LeaveAllocation.to_date))
# only consider cf leaves from current allocation
& (LeaveAllocation.from_date <= date)
& (date <= LeaveAllocation.to_date)
)
)
)
Expand Down
36 changes: 31 additions & 5 deletions erpnext/hr/doctype/leave_application/test_leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,25 +1170,51 @@ def test_get_leave_allocation_records(self):
details = get_leave_allocation_records(employee.name, add_days(cf_expiry, 1), leave_type.name)
self.assertEqual(details.get(leave_type.name), expected_data)

@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_filtered_old_cf_entries_in_get_leave_allocation_records(self):
"""Tests whether old cf entries are ignored while fetching current allocation records"""
employee = get_employee()
leave_type = create_leave_type(
leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1,
expire_carry_forwarded_leaves_after_days=90,
)

# old allocation with cf leaves
create_carry_forwarded_allocation(employee, leave_type, date="2019-01-01")
# new allocation with cf leaves
leave_alloc = create_carry_forwarded_allocation(employee, leave_type)
cf_expiry = frappe.db.get_value(
"Leave Ledger Entry", {"transaction_name": leave_alloc.name, "is_carry_forward": 1}, "to_date"
)

# test total leaves allocated before cf leave expiry
details = get_leave_allocation_records(employee.name, add_days(cf_expiry, -1), leave_type.name)
# filters out old CF leaves (15 i.e total 45)
self.assertEqual(details[leave_type.name]["total_leaves_allocated"], 30.0)


def create_carry_forwarded_allocation(employee, leave_type, date=None):
date = date or nowdate()

def create_carry_forwarded_allocation(employee, leave_type):
# initial leave allocation
leave_allocation = create_leave_allocation(
leave_type="_Test_CF_leave_expiry",
employee=employee.name,
employee_name=employee.employee_name,
from_date=add_months(nowdate(), -24),
to_date=add_months(nowdate(), -12),
from_date=add_months(date, -24),
to_date=add_months(date, -12),
carry_forward=0,
)
leave_allocation.submit()

# carry forward leave allocation
leave_allocation = create_leave_allocation(
leave_type="_Test_CF_leave_expiry",
employee=employee.name,
employee_name=employee.employee_name,
from_date=add_days(nowdate(), -84),
to_date=add_days(nowdate(), 100),
from_date=add_days(date, -84),
to_date=add_days(date, 100),
carry_forward=1,
)
leave_allocation.submit()
Expand Down