Files
Odoo-Modules/fusion_clock/tests/test_overnight.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

41 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
from datetime import date
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
@tagged('-at_install', 'post_install', 'fusion_clock')
class TestOvernight(TransactionCase):
def setUp(self):
super().setUp()
self.Schedule = self.env['fusion.clock.schedule']
self.emp = self.env['hr.employee'].create({'name': 'Nox'})
def test_overnight_hours_and_flag(self):
sch = self.Schedule.create({
'employee_id': self.emp.id, 'schedule_date': date(2026, 6, 1),
'start_time': 22.0, 'end_time': 6.0, 'break_minutes': 30.0, 'state': 'posted'})
self.assertTrue(sch.crosses_midnight)
# 22:00 -> 06:00 = 8h, minus 30m break = 7.5h
self.assertAlmostEqual(sch.planned_hours, 7.5, places=2)
def test_overnight_scheduled_out_is_next_day(self):
self.Schedule.create({
'employee_id': self.emp.id, 'schedule_date': date(2026, 6, 1),
'start_time': 22.0, 'end_time': 6.0, 'break_minutes': 0.0, 'state': 'posted'})
sin, sout = self.emp._get_fclk_scheduled_times(date(2026, 6, 1))
self.assertGreater(sout, sin)
self.assertAlmostEqual((sout - sin).total_seconds() / 3600.0, 8.0, places=1)
def test_overnight_is_allowed_by_constraint(self):
# Must not raise now that overnight is supported.
sch = self.Schedule.create({
'employee_id': self.emp.id, 'schedule_date': date(2026, 6, 2),
'start_time': 20.0, 'end_time': 4.0, 'break_minutes': 60.0, 'state': 'posted'})
self.assertAlmostEqual(sch.planned_hours, 7.0, places=2) # 8h - 1h break