1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# -*- coding: utf-8 -*-
import time
from odoo.tests.common import TransactionCase
class TestHrAttendance(TransactionCase):
"""Tests for attendance date ranges validity"""
def setUp(self):
super(TestHrAttendance, self).setUp()
self.attendance = self.env['hr.attendance']
self.test_employee = self.env['hr.employee'].create({'name': "Jacky"})
# demo data contains set up for self.test_employee
self.open_attendance = self.attendance.create({
'employee_id': self.test_employee.id,
'check_in': time.strftime('%Y-%m-10 10:00'),
})
def test_attendance_in_before_out(self):
# Make sure check_out is before check_in
with self.assertRaises(Exception):
self.my_attend = self.attendance.create({
'employee_id': self.test_employee.id,
'check_in': time.strftime('%Y-%m-10 12:00'),
'check_out': time.strftime('%Y-%m-10 11:00'),
})
def test_attendance_no_check_out(self):
# Make sure no second attandance without check_out can be created
with self.assertRaises(Exception):
self.attendance.create({
'employee_id': self.test_employee.id,
'check_in': time.strftime('%Y-%m-10 11:00'),
})
# 5 next tests : Make sure that when attendances overlap an error is raised
def test_attendance_1(self):
self.attendance.create({
'employee_id': self.test_employee.id,
'check_in': time.strftime('%Y-%m-10 07:30'),
'check_out': time.strftime('%Y-%m-10 09:00'),
})
with self.assertRaises(Exception):
self.attendance.create({
'employee_id': self.test_employee.id,
'check_in': time.strftime('%Y-%m-10 08:30'),
'check_out': time.strftime('%Y-%m-10 09:30'),
})
def test_new_attendances(self):
# Make sure attendance modification raises an error when it causes an overlap
self.attendance.create({
'employee_id': self.test_employee.id,
'check_in': time.strftime('%Y-%m-10 11:00'),
'check_out': time.strftime('%Y-%m-10 12:00'),
})
with self.assertRaises(Exception):
self.open_attendance.write({
'check_out': time.strftime('%Y-%m-10 11:30'),
})
|