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:
@@ -73,7 +73,7 @@ class TestRecurrence(TransactionCase):
|
|||||||
|
|
||||||
def test_leave_day_skipped(self):
|
def test_leave_day_skipped(self):
|
||||||
self.env['fusion.clock.leave.request'].create({
|
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)})
|
'leave_date': date(2026, 6, 8), 'date_to': date(2026, 6, 8)})
|
||||||
seed = self._seed(date(2026, 6, 1))
|
seed = self._seed(date(2026, 6, 1))
|
||||||
rule = self.Schedule.fclk_attach_recurrence(seed, {
|
rule = self.Schedule.fclk_attach_recurrence(seed, {
|
||||||
|
|||||||
@@ -3,12 +3,8 @@
|
|||||||
import json
|
import json
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
from psycopg2 import IntegrityError
|
|
||||||
|
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
from odoo.tests.common import HttpCase, TransactionCase, tagged
|
from odoo.tests.common import HttpCase, TransactionCase, tagged
|
||||||
from odoo.tools.misc import mute_logger
|
|
||||||
|
|
||||||
|
|
||||||
@tagged('-at_install', 'post_install', 'fusion_clock')
|
@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.employee.x_fclk_shift_id = cls.default_shift.id
|
||||||
cls.schedule_date = date(2026, 1, 5)
|
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({
|
self.Schedule.create({
|
||||||
'employee_id': self.employee.id,
|
'employee_id': self.employee.id,
|
||||||
'schedule_date': self.schedule_date,
|
'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'):
|
self.Schedule.create({
|
||||||
with self.env.cr.savepoint():
|
'employee_id': self.employee.id,
|
||||||
self.Schedule.create({
|
'schedule_date': self.schedule_date,
|
||||||
'employee_id': self.employee.id,
|
'start_time': 13.0, 'end_time': 17.0,
|
||||||
'schedule_date': self.schedule_date,
|
})
|
||||||
'is_off': True,
|
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):
|
def test_off_schedule_has_zero_hours(self):
|
||||||
schedule = self.Schedule.create({
|
schedule = self.Schedule.create({
|
||||||
@@ -68,15 +67,18 @@ class TestShiftPlannerModels(TransactionCase):
|
|||||||
self.assertEqual(schedule.planned_hours, 8.0)
|
self.assertEqual(schedule.planned_hours, 8.0)
|
||||||
self.assertEqual(self.Schedule.fclk_hours_display(schedule.planned_hours), '8:00')
|
self.assertEqual(self.Schedule.fclk_hours_display(schedule.planned_hours), '8:00')
|
||||||
|
|
||||||
def test_invalid_same_day_range_is_rejected(self):
|
def test_overnight_range_is_accepted(self):
|
||||||
with self.assertRaises(ValidationError):
|
# Overnight shifts (end on/before start) are supported as of 19.0.5.0.0.
|
||||||
self.Schedule.create({
|
sch = self.Schedule.create({
|
||||||
'employee_id': self.employee.id,
|
'employee_id': self.employee.id,
|
||||||
'schedule_date': date(2026, 1, 8),
|
'schedule_date': date(2026, 1, 8),
|
||||||
'start_time': 17.0,
|
'start_time': 17.0,
|
||||||
'end_time': 9.0,
|
'end_time': 9.0,
|
||||||
'break_minutes': 30,
|
'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):
|
def test_apply_planner_cell_creates_audit(self):
|
||||||
schedule_date = date(2026, 1, 9)
|
schedule_date = date(2026, 1, 9)
|
||||||
|
|||||||
Reference in New Issue
Block a user