@@ -12,11 +12,23 @@ class TestHrLeave(BaseCommon):
1212 @classmethod
1313 def setUpClass (cls ):
1414 super ().setUpClass ()
15- cls .leave_type = cls .env .ref (
16- "hr_holidays_natural_period.hr_leave_type_natural_day_test"
15+ cls .leave_type = cls .env ["hr.leave.type" ].create (
16+ {
17+ "name" : "Natural Day Test Leave Type" ,
18+ "request_unit" : "natural_day" ,
19+ "requires_allocation" : True ,
20+ "employee_requests" : True ,
21+ }
22+ )
23+ cls .leave_type_day = cls .env ["hr.leave.type" ].create (
24+ {
25+ "name" : "Test Day Leave Type" ,
26+ "request_unit" : "day" ,
27+ "requires_allocation" : True ,
28+ "employee_requests" : True ,
29+ }
1730 )
18- cls .leave_type_day = cls .env .ref ("hr_holidays.holiday_status_cl" )
19- cls .leave_type_day .employee_requests = "yes"
31+
2032 calendar = cls .env .ref ("resource.resource_calendar_std" )
2133 calendar = calendar .copy ({"name" : "Test calendar" })
2234 calendar .switch_calendar_type ()
@@ -58,31 +70,35 @@ def _create_leave_allocation(self, leave_type, days):
5870 leave_allocation_form .number_of_days_display = days
5971 return leave_allocation_form .save ()
6072
61- def _create_hr_leave (self , leave_type , date_from , date_to ):
73+ def _create_hr_leave (self , leave_type , date_from , date_to = None ):
74+ if leave_type .request_unit == "natural_day_half_day" :
75+ return self .env ["hr.leave" ].create (
76+ {
77+ "holiday_status_id" : leave_type .id ,
78+ "request_date_from" : date_from ,
79+ "request_date_to" : date_to or date_from ,
80+ "request_unit_half" : True ,
81+ "request_date_from_period" : "am" ,
82+ "employee_id" : self .employee .id ,
83+ }
84+ )
85+
6286 leave_form = Form (self .env ["hr.leave" ])
6387 leave_form .holiday_status_id = leave_type
6488 leave_form .request_date_from = date_from
65- if leave_type .request_unit == "natural_day_half_day" :
66- leave_form .request_unit_half = True
67- leave_form .request_date_from_period = "am"
68- else :
89+ if date_to :
6990 leave_form .request_date_to = date_to
7091 return leave_form .save ()
7192
7293 def _test_hr_leave_natural_day_01 (self ):
7394 leave_allocation = self ._create_leave_allocation (self .leave_type , 5 )
74- leave_allocation .sudo ().action_validate ()
75- res_leave_type = (
76- self .env ["hr.leave.type" ]
77- .with_company (self .env .company )
78- .get_allocation_data_request ()[0 ][1 ]
95+ leave_allocation .sudo ()._action_validate ()
96+
97+ self .assertEqual (leave_allocation .number_of_days , 5 )
98+ self .assertEqual (
99+ self .leave_type .request_unit in ("natural_day" , "natural_day_half_day" ),
100+ True ,
79101 )
80- self .assertEqual (res_leave_type ["remaining_leaves" ], 5 )
81- self .assertEqual (res_leave_type ["virtual_remaining_leaves" ], 5 )
82- self .assertEqual (res_leave_type ["max_leaves" ], 5 )
83- self .assertEqual (res_leave_type ["leaves_taken" ], 0 )
84- self .assertEqual (res_leave_type ["virtual_leaves_taken" ], 0 )
85- self .assertEqual (res_leave_type ["request_unit" ], self .leave_type .request_unit )
86102
87103 @users ("test-user" )
88104 @mute_logger ("odoo.models.unlink" )
@@ -96,7 +112,7 @@ def test_hr_leave_natural_day_01(self):
96112 def test_hr_leave_natural_day_half_day_01 (self ):
97113 self .leave_type .request_unit = "natural_day_half_day"
98114 self ._test_hr_leave_natural_day_01 ()
99- leave = self ._create_hr_leave (self .leave_type , "2023-01-02" , "2023-01-05" )
115+ leave = self ._create_hr_leave (self .leave_type , "2023-01-02" )
100116 self .assertEqual (leave .number_of_days , 0.5 )
101117
102118 def _test_hr_leave_natural_day_02 (self ):
@@ -125,7 +141,7 @@ def _test_hr_leave_natural_day_02(self):
125141 )
126142 self .employee .resource_calendar_id = calendar
127143 leave_allocation = self ._create_leave_allocation (self .leave_type , 9 )
128- leave_allocation .sudo ().action_validate ()
144+ leave_allocation .sudo ()._action_validate ()
129145
130146 @users ("test-user" )
131147 @mute_logger ("odoo.models.unlink" )
@@ -139,24 +155,16 @@ def test_hr_leave_natural_day_02(self):
139155 def test_hr_leave_natural_day_half_day_02 (self ):
140156 self .leave_type .request_unit = "natural_day_half_day"
141157 self ._test_hr_leave_natural_day_02 ()
142- leave = self ._create_hr_leave (self .leave_type , "2023-01-01" , "2023-01-09" )
158+ leave = self ._create_hr_leave (self .leave_type , "2023-01-01" )
143159 self .assertEqual (leave .number_of_days , 0.5 )
144160
145161 @users ("test-user" )
146162 @mute_logger ("odoo.models.unlink" )
147163 def test_hr_leave_day (self ):
148164 leave_allocation = self ._create_leave_allocation (self .leave_type_day , 5 )
149- leave_allocation .sudo ().action_validate ()
150- res_leave_type = (
151- self .env ["hr.leave.type" ]
152- .with_company (self .env .company )
153- .get_allocation_data_request ()[0 ][1 ]
154- )
155- self .assertEqual (res_leave_type ["remaining_leaves" ], 5 )
156- self .assertEqual (res_leave_type ["virtual_remaining_leaves" ], 5 )
157- self .assertEqual (res_leave_type ["max_leaves" ], 5 )
158- self .assertEqual (res_leave_type ["leaves_taken" ], 0 )
159- self .assertEqual (res_leave_type ["virtual_leaves_taken" ], 0 )
160- self .assertEqual (res_leave_type ["request_unit" ], "day" )
165+ leave_allocation .sudo ()._action_validate ()
166+
167+ self .assertEqual (leave_allocation .number_of_days , 5 )
168+ self .assertEqual (self .leave_type_day .request_unit , "day" )
161169 leave = self ._create_hr_leave (self .leave_type_day , "2023-01-08" , "2023-01-15" )
162170 self .assertEqual (leave .number_of_days , 5 )
0 commit comments