forked from itpp-labs/misc-addons
/
test_hr_attendance_constraints.py
66 lines (58 loc) · 2.57 KB
/
test_hr_attendance_constraints.py
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
63
64
65
66
# Copyright (c) 2004-2015 Odoo S.A.
# Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.tests.common import TransactionCase
import time
class TestHrAttendance(TransactionCase):
"""Tests for attendance date ranges validity"""
def setUp(self):
super(TestHrAttendance, self).setUp()
self.attendance = self.env['res.partner.attendance']
self.test_partner = self.env.ref('base.partner_demo')
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({
'partner_id': self.test_partner.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 attendance without check_out can be created
self.attendance.create({
'partner_id': self.test_partner.id,
'check_in': time.strftime('%Y-%m-10 10:00'),
})
with self.assertRaises(Exception):
self.attendance.create({
'partner_id': self.test_partner.id,
'check_in': time.strftime('%Y-%m-10 11:00'),
})
def test_check_in_while_attendance(self):
# Make sure attendance no check in while attendance is on
self.attendance.create({
'partner_id': self.test_partner.id,
'check_in': time.strftime('%Y-%m-10 08:00'),
'check_out': time.strftime('%Y-%m-10 09:30'),
})
with self.assertRaises(Exception):
self.attendance.create({
'partner_id': self.test_partner.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({
'partner_id': self.test_partner.id,
'check_in': time.strftime('%Y-%m-10 11:00'),
'check_out': time.strftime('%Y-%m-10 12:00'),
})
open_attendance = self.attendance.create({
'partner_id': self.test_partner.id,
'check_in': time.strftime('%Y-%m-10 10:00'),
})
with self.assertRaises(Exception):
open_attendance.write({
'check_out': time.strftime('%Y-%m-10 11:30'),
})