diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_attendance/tests/test_hr_attendance_constraints.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/hr_attendance/tests/test_hr_attendance_constraints.py')
| -rw-r--r-- | addons/hr_attendance/tests/test_hr_attendance_constraints.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/addons/hr_attendance/tests/test_hr_attendance_constraints.py b/addons/hr_attendance/tests/test_hr_attendance_constraints.py new file mode 100644 index 00000000..15f585f6 --- /dev/null +++ b/addons/hr_attendance/tests/test_hr_attendance_constraints.py @@ -0,0 +1,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'), + }) |
