|
| 1 | +# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 | +import pytz |
| 3 | +from datetime import datetime |
| 4 | + |
| 5 | +from odoo.tests.common import TransactionCase |
| 6 | + |
| 7 | + |
| 8 | +class TestResourceCalendar(TransactionCase): |
| 9 | + |
| 10 | + def test_fully_flexible_attendance_interval_duration(self): |
| 11 | + """ |
| 12 | + Test that the duration of a fully flexible attendance interval is correctly computed. |
| 13 | + """ |
| 14 | + calendar = self.env['resource.calendar'].create({ |
| 15 | + 'name': 'Standard Calendar', |
| 16 | + 'two_weeks_calendar': False, |
| 17 | + }) |
| 18 | + resource = self.env['resource.resource'].create({ |
| 19 | + 'name': 'Wade Wilson', |
| 20 | + 'calendar_id': False, # Fully-flexible because no calendar is set |
| 21 | + 'tz': 'America/New_York', # -04:00 UTC offset in the summer |
| 22 | + }) |
| 23 | + self.env['resource.calendar.attendance'].create({ |
| 24 | + 'name': 'TEMP', |
| 25 | + 'calendar_id': calendar.id, |
| 26 | + 'dayofweek': '2', # Wednesday |
| 27 | + 'hour_from': 14, # 18:00 UTC |
| 28 | + 'hour_to': 17, # 21:00 UTC |
| 29 | + 'date_from': datetime(2025, 6, 4, 0, 0, 0).date(), |
| 30 | + }) |
| 31 | + UTC = pytz.timezone('UTC') |
| 32 | + start_dt = datetime(2025, 6, 4, 18, 0, 0).astimezone(UTC) |
| 33 | + end_dt = datetime(2025, 6, 4, 21, 0, 0).astimezone(UTC) |
| 34 | + result_per_resource_id = calendar._attendance_intervals_batch( |
| 35 | + start_dt, end_dt, resource |
| 36 | + ) |
| 37 | + start, end, attendance = result_per_resource_id[resource.id]._items[0] |
| 38 | + # For a flexible resource, we expect the output times to match the |
| 39 | + # input times exactly, since the resource has no fixed calendar. |
| 40 | + # Further, the dummy attendance that is created should have a duration |
| 41 | + # equal to the difference between the start and end times. |
| 42 | + self.assertEqual(start, start_dt, "Output start time should match the input start time") |
| 43 | + self.assertEqual(end, end_dt, "Output end time should match the input end time") |
| 44 | + self.assertEqual(attendance.duration_hours, 3.0, "Attendance duration should be 3 hours") |
| 45 | + self.assertEqual(attendance.duration_days, 0.125, "Attendance duration should be 0.125 days (3 hours)") |
0 commit comments