xxxxxxxxxx
1
# -*- coding: utf-8 -*-
2
3
from odoo.tests.common import TransactionCase
4
import time
5
6
7
class TestHrAttendance(TransactionCase):
8
"""Tests for attendance date ranges validity"""
9
10
def setUp(self):
11
super(TestHrAttendance, self).setUp()
12
self.attendance = self.env['hr.attendance']
13
self.test_employee = self.browse_ref('hr.employee_qdp')
14
# demo data contains set up for self.test_employee
15
16
def test_attendance_in_before_out(self):
17
# Make sure check_out is before check_in
18
with self.assertRaises(Exception):
19
self.my_attend = self.attendance.create({
20
'employee_id': self.test_employee.id,
21
'check_in': time.strftime('%Y-%m-10 12:00'),
22
'check_out': time.strftime('%Y-%m-10 11:00'),
23
})
24
25
def test_attendance_no_check_out(self):
26
# Make sure no second attandance without check_out can be created
27
self.attendance.create({
28
'employee_id': self.test_employee.id,
29
'check_in': time.strftime('%Y-%m-10 10:00'),
30
})
31
with self.assertRaises(Exception):
32
self.attendance.create({
33
'employee_id': self.test_employee.id,
34
'check_in': time.strftime('%Y-%m-10 11:00'),
35
})
36
37
# 5 next tests : Make sure that when attendances overlap an error is raised
38
def test_attendance_1(self):
39
with self.assertRaises(Exception):
40
self.attendance.create({
41
'employee_id': self.test_employee.id,
42
'check_in': time.strftime('%Y-%m-10 08:30'),
43
'check_out': time.strftime('%Y-%m-10 09:30'),
44
})
45
46
def test_attendance_2(self):
47
with self.assertRaises(Exception):
48
self.attendance.create({
49
'employee_id': self.test_employee.id,
50
'check_in': time.strftime('%Y-%m-10 07:30'),
51
'check_out': time.strftime('%Y-%m-10 08:30'),
52
})
53
54
def test_attendance_3(self):
55
with self.assertRaises(Exception):
56
self.attendance.create({
57
'employee_id': self.test_employee.id,
58
'check_in': time.strftime('%Y-%m-10 07:30'),
59
'check_out': time.strftime('%Y-%m-10 09:30'),
60
})
61
62
def test_attendance_4(self):
63
with self.assertRaises(Exception):
64
self.attendance.create({
65
'employee_id': self.test_employee.id,
66
'check_in': time.strftime('%Y-%m-10 08:15'),
67
'check_out': time.strftime('%Y-%m-10 08:45'),
68
})
69
70
def test_attendance_5(self):
71
self.attendance.create({
72
'employee_id': self.test_employee.id,
73
'check_in': time.strftime('%Y-%m-10 10:00'),
74
})
75
with self.assertRaises(Exception):
76
self.attendance.create({
77
'employee_id': self.test_employee.id,
78
'check_in': time.strftime('%Y-%m-10 09:30'),
79
'check_out': time.strftime('%Y-%m-10 10:30'),
80
})
81
82
def test_new_attendances(self):
83
# Make sure attendance modification raises an error when it causes an overlap
84
self.attendance.create({
85
'employee_id': self.test_employee.id,
86
'check_in': time.strftime('%Y-%m-10 11:00'),
87
'check_out': time.strftime('%Y-%m-10 12:00'),
88
})
89
open_attendance = self.attendance.create({
90
'employee_id': self.test_employee.id,
91
'check_in': time.strftime('%Y-%m-10 10:00'),
92
})
93
with self.assertRaises(Exception):
94
open_attendance.write({
95
'check_out': time.strftime('%Y-%m-10 11:30'),
96
})
97
已复制