@@ -699,8 +699,7 @@ def test_leave_balance_near_allocaton_expiry(self):
699699 leave_type_name = "_Test_CF_leave_expiry" ,
700700 is_carry_forward = 1 ,
701701 expire_carry_forwarded_leaves_after_days = 90 ,
702- )
703- leave_type .insert ()
702+ ).insert ()
704703
705704 create_carry_forwarded_allocation (employee , leave_type )
706705 details = get_leave_balance_on (
@@ -924,17 +923,51 @@ def test_get_leave_details_for_dashboard(self):
924923 self .assertEqual (leave_allocation ["remaining_leaves" ], 26 )
925924
926925 @set_holiday_list ("Salary Slip Test Holiday List" , "_Test Company" )
927- def test_get_leave_allocation_records (self ):
926+ def test_leave_details_with_expired_cf_leaves (self ):
928927 employee = get_employee ()
929928 leave_type = create_leave_type (
930929 leave_type_name = "_Test_CF_leave_expiry" ,
931930 is_carry_forward = 1 ,
932931 expire_carry_forwarded_leaves_after_days = 90 ,
932+ ).insert ()
933+
934+ leave_alloc = create_carry_forwarded_allocation (employee , leave_type )
935+ cf_expiry = frappe .db .get_value (
936+ "Leave Ledger Entry" , {"transaction_name" : leave_alloc .name , "is_carry_forward" : 1 }, "to_date"
933937 )
934- leave_type .insert ()
938+
939+ # all leaves available before cf leave expiry
940+ leave_details = get_leave_details (employee .name , add_days (cf_expiry , - 1 ))
941+ self .assertEqual (leave_details ["leave_allocation" ][leave_type .name ]["remaining_leaves" ], 30.0 )
942+
943+ # cf leaves expired
944+ leave_details = get_leave_details (employee .name , add_days (cf_expiry , 1 ))
945+ expected_data = {
946+ "total_leaves" : 30.0 ,
947+ "expired_leaves" : 15.0 ,
948+ "leaves_taken" : 0.0 ,
949+ "leaves_pending_approval" : 0.0 ,
950+ "remaining_leaves" : 15.0 ,
951+ }
952+ self .assertEqual (leave_details ["leave_allocation" ][leave_type .name ], expected_data )
953+
954+ @set_holiday_list ("Salary Slip Test Holiday List" , "_Test Company" )
955+ def test_get_leave_allocation_records (self ):
956+ """Tests if total leaves allocated before and after carry forwarded leave expiry is same"""
957+ employee = get_employee ()
958+ leave_type = create_leave_type (
959+ leave_type_name = "_Test_CF_leave_expiry" ,
960+ is_carry_forward = 1 ,
961+ expire_carry_forwarded_leaves_after_days = 90 ,
962+ ).insert ()
935963
936964 leave_alloc = create_carry_forwarded_allocation (employee , leave_type )
937- details = get_leave_allocation_records (employee .name , getdate (), leave_type .name )
965+ cf_expiry = frappe .db .get_value (
966+ "Leave Ledger Entry" , {"transaction_name" : leave_alloc .name , "is_carry_forward" : 1 }, "to_date"
967+ )
968+
969+ # test total leaves allocated before cf leave expiry
970+ details = get_leave_allocation_records (employee .name , add_days (cf_expiry , - 1 ), leave_type .name )
938971 expected_data = {
939972 "from_date" : getdate (leave_alloc .from_date ),
940973 "to_date" : getdate (leave_alloc .to_date ),
@@ -945,6 +978,11 @@ def test_get_leave_allocation_records(self):
945978 }
946979 self .assertEqual (details .get (leave_type .name ), expected_data )
947980
981+ # test leaves allocated after carry forwarded leaves expiry, should be same thoroughout allocation period
982+ # cf leaves should show up under expired or taken leaves later
983+ details = get_leave_allocation_records (employee .name , add_days (cf_expiry , 1 ), leave_type .name )
984+ self .assertEqual (details .get (leave_type .name ), expected_data )
985+
948986
949987def create_carry_forwarded_allocation (employee , leave_type ):
950988 # initial leave allocation
0 commit comments