@@ -242,3 +242,32 @@ def test_earned_leave_allocation_if_leave_policy_assignment_submitted_after_peri
242
242
"Leave Allocation" , {"leave_policy_assignment" : assignment .name }, "new_leaves_allocated"
243
243
)
244
244
self .assertEqual (earned_leave_allocation , annual_earned_leaves )
245
+
246
+ def test_earned_leave_allocation_for_leave_period_spanning_two_years (self ):
247
+ first_year_start_date = get_year_start (getdate ())
248
+ second_year_end_date = get_year_ending (add_months (first_year_start_date , 12 ))
249
+ leave_period = create_leave_period (first_year_start_date , second_year_end_date )
250
+
251
+ # assignment during mid second year
252
+ frappe .flags .current_date = add_months (second_year_end_date , - 6 )
253
+ leave_type = create_leave_type (
254
+ leave_type_name = "_Test Earned Leave" , is_earned_leave = True , allocate_on_day = "Last Day"
255
+ )
256
+ annual_earned_leaves = 24
257
+ leave_policy = create_leave_policy (leave_type = leave_type , annual_allocation = annual_earned_leaves )
258
+ leave_policy .submit ()
259
+
260
+ data = {
261
+ "assignment_based_on" : "Leave Period" ,
262
+ "leave_policy" : leave_policy .name ,
263
+ "leave_period" : leave_period .name ,
264
+ }
265
+ assignment = create_assignment (self .employee .name , frappe ._dict (data ))
266
+ assignment .submit ()
267
+
268
+ earned_leave_allocation = frappe .get_value (
269
+ "Leave Allocation" , {"leave_policy_assignment" : assignment .name }, "new_leaves_allocated"
270
+ )
271
+ # months passed (18) are calculated correctly but total allocation of 36 exceeds 24 hence 24
272
+ # this upper cap is intentional, without that 36 leaves would be allocated correctly
273
+ self .assertEqual (earned_leave_allocation , 24 )
0 commit comments