8
8
9
9
from odoo .exceptions import UserError , ValidationError
10
10
11
- from odoo .addons .hr_holidays .tests .common import TestHrHolidaysBase
11
+ from odoo .addons .hr_holidays .tests .common import TestHrHolidaysCommon
12
+ from odoo .addons .mail .tests .common import mail_new_test_user
12
13
13
14
14
- class TimesheetHolidayTest (TestHrHolidaysBase ):
15
+ class TimesheetHolidayTest (TestHrHolidaysCommon ):
15
16
def setUp (self ):
16
17
super (TimesheetHolidayTest , self ).setUp ()
17
- self .leave = self .env ["hr.holidays " ]
18
+ self .leave = self .env ["hr.leave " ]
18
19
self .project = self .env ["project.project" ]
19
- self .sheet = self .env ["hr_timesheet_sheet.sheet" ]
20
- self .employee = self .env .ref ("hr.employee_qdp" )
20
+ self .sheet = self .env ["hr_timesheet.sheet" ]
21
+ # grant analytic account access
22
+ self .user_hruser .groups_id += self .env .ref ("analytic.group_analytic_accounting" )
23
+
24
+ self .employee_user = mail_new_test_user (
25
+ self .env , login = "Test Emp" , groups = "base.group_user"
26
+ )
27
+ self .employee = self .env ["hr.employee" ].create (
28
+ {
29
+ "name" : "Test Employee" ,
30
+ "user_id" : self .employee_user .id ,
31
+ "department_id" : self .rd_dept .id ,
32
+ }
33
+ )
21
34
self .sl = self .env .ref ("hr_holidays.holiday_status_sl" )
22
35
23
36
def _create_timesheet (self , employee , date_from , date_to ):
@@ -40,6 +53,7 @@ def test_all(self):
40
53
"allow_timesheets" : False ,
41
54
}
42
55
)
56
+ project ._create_analytic_account ()
43
57
account = project .analytic_account_id
44
58
with self .assertRaises (ValidationError ):
45
59
# Create analytic account
@@ -48,30 +62,29 @@ def test_all(self):
48
62
account .write ({"is_leave_account" : True })
49
63
# Link sick leave to analytic account
50
64
sl = self .sl
51
- sl .write ({"project_id " : project .id })
65
+ sl .write ({"timesheet_project_id " : project .id })
52
66
# Confirm leave and check hours added to account
53
67
hours_before = sum (account .line_ids .mapped ("amount" ))
54
- # Holidays.sudo (self.user_employee_id)
55
- hol_empl_grp = self .leave .sudo (self .user_hruser_id )
68
+ # Holidays.with_user (self.user_employee_id)
69
+ hol_empl_grp = self .leave .with_user (self .user_hruser_id )
56
70
leave = hol_empl_grp .create (
57
71
{
58
72
"name" : "One week sick leave" ,
59
73
"employee_id" : self .employee_emp_id ,
60
74
"holiday_status_id" : self .sl .id ,
61
75
"date_from" : (datetime .today () - relativedelta (days = 7 )),
62
76
"date_to" : datetime .today (),
63
- "number_of_days_temp" : 7.0 ,
64
77
}
65
78
)
66
79
self .assertEqual (
67
80
leave .state ,
68
81
"confirm" ,
69
82
"hr_holidays: newly created leave request should be in " "confirm state" ,
70
83
)
71
- leave .sudo (self .user_hruser_id ).action_approve ()
84
+ leave .with_user (self .user_hruser_id ).action_approve ()
72
85
73
86
hours_after = sum (account .line_ids .mapped ("unit_amount" ))
74
- self .assertEqual (hours_after - hours_before , 35 .0 )
87
+ self .assertEqual (hours_after - hours_before , 28 .0 )
75
88
76
89
# Test editing of lines forbidden
77
90
self .assertRaises (
@@ -81,7 +94,7 @@ def test_all(self):
81
94
# Test force editing of lines allowed
82
95
account .line_ids [0 ].with_context (force_write = True ).write ({"unit_amount" : 5.0 })
83
96
hours_after = sum (account .line_ids .mapped ("unit_amount" ))
84
- self .assertEqual (hours_after - hours_before , 33 .0 )
97
+ self .assertEqual (hours_after - hours_before , 26 .0 )
85
98
# Ensure the user_id defined on generated analytic lines is the user
86
99
# set on the employee
87
100
user_employee = self .env ["hr.employee" ].browse (self .employee_emp_id ).user_id
@@ -100,21 +113,21 @@ def test_timesheet(self):
100
113
"allow_timesheets" : True ,
101
114
}
102
115
)
116
+ project ._create_analytic_account ()
103
117
account = project .analytic_account_id
104
118
account .write ({"is_leave_account" : True })
105
119
# Link sick leave to analytic account
106
120
sl = self .sl
107
121
sl .write ({"analytic_account_id" : account .id })
108
122
109
- hol_empl_grp = self .leave .sudo (self .user_employee_id )
123
+ hol_empl_grp = self .leave .with_user (self .user_employee_id )
110
124
leave = hol_empl_grp .create (
111
125
{
112
126
"name" : "One week sick leave" ,
113
127
"employee_id" : self .employee_emp_id ,
114
128
"holiday_status_id" : self .sl .id ,
115
129
"date_from" : time .strftime ("1900-01-06" ),
116
130
"date_to" : time .strftime ("1900-01-12" ),
117
- "number_of_days_temp" : 7.0 ,
118
131
}
119
132
)
120
133
with self .assertRaises (UserError ):
@@ -128,6 +141,7 @@ def test_allocation(self):
128
141
"allow_timesheets" : True ,
129
142
}
130
143
)
144
+ project ._create_analytic_account ()
131
145
account = project .analytic_account_id
132
146
account .write ({"is_leave_account" : True })
133
147
# Link sick leave to analytic account
@@ -139,9 +153,7 @@ def test_allocation(self):
139
153
"holiday_status_id" : self .sl .id ,
140
154
"date_from" : time .strftime ("%Y-%m-06" ),
141
155
"date_to" : time .strftime ("%Y-%m-12" ),
142
- "number_of_days_temp" : 7.0 ,
143
156
"employee_id" : self .employee .id ,
144
- "type" : "add" ,
145
157
}
146
158
)
147
159
leave .action_approve ()
@@ -160,26 +172,27 @@ def test_timesheet_half_day(self):
160
172
"allow_timesheets" : False ,
161
173
}
162
174
)
175
+ project ._create_analytic_account ()
163
176
account = project .analytic_account_id
164
177
project .write ({"allow_timesheets" : True })
165
178
account .write ({"is_leave_account" : True })
166
179
# Link sick leave to analytic account
167
180
sl = self .sl
168
- sl .write ({"project_id " : project .id })
181
+ sl .write ({"timesheet_project_id " : project .id })
169
182
# Confirm leave and check hours added to account
170
183
hours_before = sum (account .line_ids .mapped ("amount" ))
171
- # Holidays.sudo(self.user_employee_id)
172
- hol_empl_grp = self .leave .sudo (self .user_hruser_id )
184
+ # Holidays.with_user(self.user_employee_id)
185
+ hol_empl_grp = self .leave .with_user (self .user_hruser_id )
186
+ leave_date = datetime .today () + (relativedelta (days = 10 ))
173
187
leave = hol_empl_grp .create (
174
188
{
175
189
"name" : "One day and a half sick leave" ,
176
190
"employee_id" : self .employee_emp_id ,
177
191
"holiday_status_id" : self .sl .id ,
178
- "date_from" : (datetime .today () - relativedelta (hours = 10.5 )),
179
- "date_to" : datetime .today (),
180
- "number_of_days_temp" : 1.5 ,
192
+ "date_from" : leave_date - relativedelta (hours = 10.5 ),
193
+ "date_to" : leave_date ,
181
194
}
182
195
)
183
- leave .sudo (self .user_hruser_id ).action_approve ()
196
+ leave .with_user (self .user_hruser_id ).action_approve ()
184
197
hours_after = sum (account .line_ids .mapped ("unit_amount" ))
185
- self .assertEqual (hours_after - hours_before , 10 .5 )
198
+ self .assertEqual (hours_after - hours_before , 3 .5 )
0 commit comments