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