From 53c292083f3c25bb9899f5f577313e8a97030204 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Thu, 4 Jun 2026 21:38:29 -0400 Subject: [PATCH] test(fusion_clock): update tests for dropped unique + overnight; fix leave reason test_unique_employee_date_schedule -> test_multiple_shifts_per_day_allowed; test_invalid_same_day_range_is_rejected -> test_overnight_range_is_accepted; add required reason to the recurrence leave-skip test. Co-Authored-By: Claude Opus 4.8 (1M context) --- fusion_clock/tests/test_recurrence.py | 2 +- fusion_clock/tests/test_shift_planner.py | 46 ++++++++++++------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/fusion_clock/tests/test_recurrence.py b/fusion_clock/tests/test_recurrence.py index f7fdba58..d47c79e0 100644 --- a/fusion_clock/tests/test_recurrence.py +++ b/fusion_clock/tests/test_recurrence.py @@ -73,7 +73,7 @@ class TestRecurrence(TransactionCase): def test_leave_day_skipped(self): self.env['fusion.clock.leave.request'].create({ - 'employee_id': self.emp.id, + 'employee_id': self.emp.id, 'reason': 'Vacation', 'leave_date': date(2026, 6, 8), 'date_to': date(2026, 6, 8)}) seed = self._seed(date(2026, 6, 1)) rule = self.Schedule.fclk_attach_recurrence(seed, { diff --git a/fusion_clock/tests/test_shift_planner.py b/fusion_clock/tests/test_shift_planner.py index 60b1299e..112b27f8 100644 --- a/fusion_clock/tests/test_shift_planner.py +++ b/fusion_clock/tests/test_shift_planner.py @@ -3,12 +3,8 @@ import json from datetime import date, timedelta -from psycopg2 import IntegrityError - from odoo import fields -from odoo.exceptions import ValidationError from odoo.tests.common import HttpCase, TransactionCase, tagged -from odoo.tools.misc import mute_logger @tagged('-at_install', 'post_install', 'fusion_clock') @@ -34,19 +30,22 @@ class TestShiftPlannerModels(TransactionCase): cls.employee.x_fclk_shift_id = cls.default_shift.id cls.schedule_date = date(2026, 1, 5) - def test_unique_employee_date_schedule(self): + def test_multiple_shifts_per_day_allowed(self): + # The hard one-shift-per-day UNIQUE was dropped in 19.0.5.0.0 to support + # split shifts; the day-plan resolves several rows into one work-window. self.Schedule.create({ 'employee_id': self.employee.id, 'schedule_date': self.schedule_date, - 'is_off': True, + 'start_time': 8.0, 'end_time': 12.0, }) - with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'): - with self.env.cr.savepoint(): - self.Schedule.create({ - 'employee_id': self.employee.id, - 'schedule_date': self.schedule_date, - 'is_off': True, - }) + self.Schedule.create({ + 'employee_id': self.employee.id, + 'schedule_date': self.schedule_date, + 'start_time': 13.0, 'end_time': 17.0, + }) + self.assertEqual(self.Schedule.search_count([ + ('employee_id', '=', self.employee.id), + ('schedule_date', '=', self.schedule_date)]), 2) def test_off_schedule_has_zero_hours(self): schedule = self.Schedule.create({ @@ -68,15 +67,18 @@ class TestShiftPlannerModels(TransactionCase): self.assertEqual(schedule.planned_hours, 8.0) self.assertEqual(self.Schedule.fclk_hours_display(schedule.planned_hours), '8:00') - def test_invalid_same_day_range_is_rejected(self): - with self.assertRaises(ValidationError): - self.Schedule.create({ - 'employee_id': self.employee.id, - 'schedule_date': date(2026, 1, 8), - 'start_time': 17.0, - 'end_time': 9.0, - 'break_minutes': 30, - }) + def test_overnight_range_is_accepted(self): + # Overnight shifts (end on/before start) are supported as of 19.0.5.0.0. + sch = self.Schedule.create({ + 'employee_id': self.employee.id, + 'schedule_date': date(2026, 1, 8), + 'start_time': 17.0, + 'end_time': 9.0, + 'break_minutes': 30, + }) + self.assertTrue(sch.crosses_midnight) + # 17:00 -> 09:00 = 16h, minus 30m break = 15.5h + self.assertAlmostEqual(sch.planned_hours, 15.5, places=2) def test_apply_planner_cell_creates_audit(self): schedule_date = date(2026, 1, 9)