# -*- coding: utf-8 -*- # Copyright 2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) from datetime import date from odoo.exceptions import ValidationError from odoo.tests import tagged from odoo.tests.common import TransactionCase @tagged('-at_install', 'post_install', 'fusion_clock') class TestOpenShift(TransactionCase): def setUp(self): super().setUp() self.S = self.env['fusion.clock.schedule'] def test_open_shift_needs_no_employee_and_gets_company(self): sch = self.S.create({ 'is_open': True, 'schedule_date': date(2026, 6, 1), 'start_time': 9.0, 'end_time': 17.0, 'state': 'posted'}) self.assertFalse(sch.employee_id) self.assertTrue(sch.company_id, "open shift falls back to the active company") def test_assigned_shift_requires_employee(self): with self.assertRaises(ValidationError): self.S.create({ 'schedule_date': date(2026, 6, 1), 'start_time': 9.0, 'end_time': 17.0}) def test_two_open_shifts_same_day_allowed(self): d = date(2026, 6, 1) self.S.create({'is_open': True, 'schedule_date': d, 'start_time': 8.0, 'end_time': 12.0}) self.S.create({'is_open': True, 'schedule_date': d, 'start_time': 13.0, 'end_time': 17.0}) self.assertEqual( self.S.search_count([('is_open', '=', True), ('schedule_date', '=', d)]), 2) def test_split_shift_for_same_employee_allowed(self): emp = self.env['hr.employee'].create({'name': 'Splitter'}) d = date(2026, 6, 1) self.S.create({'employee_id': emp.id, 'schedule_date': d, 'start_time': 8.0, 'end_time': 12.0}) self.S.create({'employee_id': emp.id, 'schedule_date': d, 'start_time': 13.0, 'end_time': 17.0}) self.assertEqual( self.S.search_count([('employee_id', '=', emp.id), ('schedule_date', '=', d)]), 2, "the hard one-shift-per-day uniqueness is gone")