6
6
from frappe .utils import add_months , get_first_day , get_year_ending , getdate
7
7
8
8
from hrms .hr .doctype .leave_application .test_leave_application import get_employee , get_leave_period
9
+ from hrms .hr .doctype .leave_period .test_leave_period import create_leave_period
9
10
from hrms .hr .doctype .leave_policy .test_leave_policy import create_leave_policy
10
11
from hrms .hr .doctype .leave_policy_assignment .leave_policy_assignment import (
12
+ create_assignment ,
11
13
create_assignment_for_multiple_employees ,
12
14
)
15
+ from hrms .hr .doctype .leave_type .test_leave_type import create_leave_type
13
16
14
17
test_dependencies = ["Employee" ]
15
18
@@ -20,6 +23,7 @@ def setUp(self):
20
23
"Leave Period" ,
21
24
"Leave Application" ,
22
25
"Leave Allocation" ,
26
+ "Leave Policy" ,
23
27
"Leave Policy Assignment" ,
24
28
"Leave Ledger Entry" ,
25
29
]:
@@ -117,6 +121,49 @@ def test_pro_rated_leave_allocation(self):
117
121
# pro-rated leave allocation for 9 months
118
122
self .assertEqual (allocation , 9 )
119
123
124
+ # tests no of leaves for passed months if assignment is based on Leave Period / Joining Date
125
+ def test_get_leaves_for_passed_months (self ):
126
+ first_day = get_first_day (getdate ())
127
+ annual_allocation = 10
128
+ leave_type = create_leave_type (
129
+ leave_type_name = "_Test Earned Leave" , is_earned_leave = True , allocate_on_day = "First Day"
130
+ )
131
+ leave_policy = create_leave_policy (leave_type = leave_type , annual_allocation = annual_allocation )
132
+ leave_policy .submit ()
133
+
134
+ data = {
135
+ "assignment_based_on" : "Joining Date" ,
136
+ "leave_policy" : leave_policy .name ,
137
+ }
138
+
139
+ self .employee .date_of_joining = add_months (first_day , - 5 )
140
+ self .employee .save ()
141
+ assignment = create_assignment (self .employee .name , frappe ._dict (data ))
142
+ new_leaves_allocated = assignment .get_leaves_for_passed_months (
143
+ annual_allocation , leave_type , self .employee .date_of_joining
144
+ )
145
+ self .assertEqual (new_leaves_allocated , 5 )
146
+
147
+ self .employee .date_of_joining = add_months (first_day , - 35 )
148
+ self .employee .save ()
149
+ assignment = create_assignment (self .employee .name , frappe ._dict (data ))
150
+ new_leaves_allocated = assignment .get_leaves_for_passed_months (
151
+ annual_allocation , leave_type , self .employee .date_of_joining
152
+ )
153
+ self .assertEqual (new_leaves_allocated , 30 )
154
+
155
+ leave_period = create_leave_period (add_months (first_day , - 23 ), first_day )
156
+ data = {
157
+ "assignment_based_on" : "Leave Period" ,
158
+ "leave_policy" : leave_policy .name ,
159
+ "leave_period" : leave_period .name ,
160
+ }
161
+ assignment = create_assignment (self .employee .name , frappe ._dict (data ))
162
+ new_leaves_allocated = assignment .get_leaves_for_passed_months (
163
+ annual_allocation , leave_type , self .employee .date_of_joining
164
+ )
165
+ self .assertEqual (new_leaves_allocated , 20 )
166
+
120
167
def test_pro_rated_leave_allocation_for_custom_date_range (self ):
121
168
leave_type = frappe .get_doc (
122
169
{
0 commit comments