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) <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user