Files
Odoo-Modules/fusion_clock/tests/test_open_shift.py
gsinghpal 68aaa132ee feat(fusion_clock): schedule parity — overnight, split shifts, open shifts [B1-B3]
is_open + crosses_midnight fields; employee_id optional (open shifts);
company_id computed w/ env.company fallback; drop hard one-per-day UNIQUE
(allow split + open). Overnight math in planned_hours/_check_schedule_times/
scheduled_times. _get_fclk_day_plan resolves multiple posted rows into ONE
work-window so penalties/overtime/absence stay correct. Migration drops the
old constraint defensively. Tests for overnight, window, open shifts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 21:04:58 -04:00

47 lines
1.9 KiB
Python

# -*- 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")