From b848b77815a21e60fa2e7082b238a84b91adec41 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 22 Feb 2023 09:26:33 +0530 Subject: [PATCH] test: leave details with expired cf leaves --- .../test_leave_application.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 749e4c2d4f2..45e9a87428e 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -990,6 +990,35 @@ class TestLeaveApplication(unittest.TestCase): } self.assertEqual(leave_allocation, expected) + @set_holiday_list("Salary Slip Test Holiday List", "_Test Company") + def test_leave_details_with_expired_cf_leaves(self): + 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" + ) + + # 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 + leave_details = get_leave_details(employee.name, add_days(cf_expiry, 1)) + expected_data = { + "total_leaves": 30.0, + "expired_leaves": 15.0, + "leaves_taken": 0.0, + "leaves_pending_approval": 0.0, + "remaining_leaves": 15.0, + } + self.assertEqual(leave_details["leave_allocation"][leave_type.name], expected_data) + @set_holiday_list("Salary Slip Test Holiday List", "_Test Company") def test_get_leave_allocation_records(self): """Tests if total leaves allocated before and after carry forwarded leave expiry is same"""