mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-02 13:08:27 +00:00
test: leave details with application across and after cf leave expiry
This commit is contained in:
@@ -96,6 +96,9 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
from_date = get_year_start(getdate())
|
||||
to_date = get_year_ending(getdate())
|
||||
self.holiday_list = make_holiday_list(from_date=from_date, to_date=to_date)
|
||||
list_without_weekly_offs = make_holiday_list(
|
||||
"Holiday List w/o Weekly Offs", from_date=from_date, to_date=to_date, add_weekly_offs=False
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Leave Type", "_Test Leave Type"):
|
||||
frappe.get_doc(
|
||||
@@ -990,8 +993,12 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
}
|
||||
self.assertEqual(leave_allocation, expected)
|
||||
|
||||
@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
|
||||
@set_holiday_list("Holiday List w/o Weekly Offs", "_Test Company")
|
||||
def test_leave_details_with_expired_cf_leaves(self):
|
||||
"""Tests leave details:
|
||||
Case 1: All leaves available before cf leave expiry
|
||||
Case 2: Remaining Leaves after cf leave expiry
|
||||
"""
|
||||
employee = get_employee()
|
||||
leave_type = create_leave_type(
|
||||
leave_type_name="_Test_CF_leave_expiry",
|
||||
@@ -1004,11 +1011,11 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
"Leave Ledger Entry", {"transaction_name": leave_alloc.name, "is_carry_forward": 1}, "to_date"
|
||||
)
|
||||
|
||||
# all leaves available before cf leave expiry
|
||||
# case 1: all leaves available before cf leave expiry
|
||||
leave_details = get_leave_details(employee.name, add_days(cf_expiry, -1))
|
||||
self.assertEqual(leave_details["leave_allocation"][leave_type.name]["remaining_leaves"], 30.0)
|
||||
|
||||
# cf leaves expired
|
||||
# case 2: cf leaves expired
|
||||
leave_details = get_leave_details(employee.name, add_days(cf_expiry, 1))
|
||||
expected_data = {
|
||||
"total_leaves": 30.0,
|
||||
@@ -1017,6 +1024,79 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
"leaves_pending_approval": 0.0,
|
||||
"remaining_leaves": 15.0,
|
||||
}
|
||||
|
||||
self.assertEqual(leave_details["leave_allocation"][leave_type.name], expected_data)
|
||||
|
||||
@set_holiday_list("Holiday List w/o Weekly Offs", "_Test Company")
|
||||
def test_leave_details_with_application_across_cf_expiry(self):
|
||||
"""Tests leave details with leave application across cf expiry, such that:
|
||||
cf leaves are partially expired and partially consumed
|
||||
"""
|
||||
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,
|
||||
).insert()
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
# leave application across cf expiry
|
||||
application = make_leave_application(
|
||||
employee.name,
|
||||
cf_expiry,
|
||||
add_days(cf_expiry, 3),
|
||||
leave_type.name,
|
||||
)
|
||||
|
||||
leave_details = get_leave_details(employee.name, add_days(cf_expiry, 4))
|
||||
expected_data = {
|
||||
"total_leaves": 30.0,
|
||||
"expired_leaves": 14.0,
|
||||
"leaves_taken": 4.0,
|
||||
"leaves_pending_approval": 0.0,
|
||||
"remaining_leaves": 12.0,
|
||||
}
|
||||
|
||||
self.assertEqual(leave_details["leave_allocation"][leave_type.name], expected_data)
|
||||
|
||||
@set_holiday_list("Holiday List w/o Weekly Offs", "_Test Company")
|
||||
def test_leave_details_with_application_after_cf_expiry(self):
|
||||
"""Tests leave details with leave application after cf expiry, such that:
|
||||
cf leaves are completely expired and only newly allocated leaves are consumed
|
||||
"""
|
||||
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,
|
||||
).insert()
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
# leave application after cf expiry
|
||||
application = make_leave_application(
|
||||
employee.name,
|
||||
add_days(cf_expiry, 1),
|
||||
add_days(cf_expiry, 4),
|
||||
leave_type.name,
|
||||
)
|
||||
|
||||
leave_details = get_leave_details(employee.name, add_days(cf_expiry, 4))
|
||||
expected_data = {
|
||||
"total_leaves": 30.0,
|
||||
"expired_leaves": 15.0,
|
||||
"leaves_taken": 4.0,
|
||||
"leaves_pending_approval": 0.0,
|
||||
"remaining_leaves": 11.0,
|
||||
}
|
||||
|
||||
self.assertEqual(leave_details["leave_allocation"][leave_type.name], expected_data)
|
||||
|
||||
@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
|
||||
|
||||
@@ -1587,9 +1587,9 @@ def setup_test():
|
||||
frappe.db.set_value("HR Settings", None, "leave_approval_notification_template", None)
|
||||
|
||||
|
||||
def make_holiday_list(list_name=None, from_date=None, to_date=None):
|
||||
if not (from_date and to_date):
|
||||
fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())
|
||||
|
||||
def make_holiday_list(list_name=None, from_date=None, to_date=None, add_weekly_offs=True):
|
||||
fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())
|
||||
name = list_name or "Salary Slip Test Holiday List"
|
||||
|
||||
frappe.delete_doc_if_exists("Holiday List", name, force=True)
|
||||
@@ -1600,10 +1600,13 @@ def make_holiday_list(list_name=None, from_date=None, to_date=None):
|
||||
"holiday_list_name": name,
|
||||
"from_date": from_date or fiscal_year[1],
|
||||
"to_date": to_date or fiscal_year[2],
|
||||
"weekly_off": "Sunday",
|
||||
}
|
||||
).insert()
|
||||
holiday_list.get_weekly_off_dates()
|
||||
|
||||
if add_weekly_offs:
|
||||
holiday_list.weekly_off = "Sunday"
|
||||
holiday_list.get_weekly_off_dates()
|
||||
|
||||
holiday_list.save()
|
||||
holiday_list = holiday_list.name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user