Real install verified on the Westin clone; these were test-only bugs:
- Task-create tests hardcoded scheduled_date 2026-06-03, now in the past, which
the base _check_no_overlap rejects ('Cannot schedule tasks in the past'). Use
future dates (tz test pins a future July date so Toronto stays EDT for the
9:00->13:00 UTC assertion).
- Service-rate resolver tests created rows with seeded codes (callout_standard_normal,
per_km) -> UNIQUE(code) violation post-install. Assert against the seed instead.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from datetime import date
|
|
from odoo.tests.common import TransactionCase, tagged
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestTaskTz(TransactionCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
# _compute_datetimes resolves company resource-calendar tz FIRST, then user tz.
|
|
# Set BOTH to Toronto so the UTC assertion and the round-trip are deterministic.
|
|
cls.env.user.tz = 'America/Toronto'
|
|
cal = cls.env.company.resource_calendar_id
|
|
if cal:
|
|
cal.tz = 'America/Toronto'
|
|
# technician_id is required (domain x_fc_is_field_staff=True) -> make a field tech.
|
|
cls.tech = cls.env['res.users'].create({
|
|
'name': 'TZ Test Tech',
|
|
'login': 'tz_test_tech_svcbook',
|
|
'x_fc_is_field_staff': True,
|
|
})
|
|
# A FUTURE date in July so the task is not "in the past" (the base
|
|
# _check_no_overlap constraint rejects past dates) and Toronto is firmly
|
|
# in EDT (-4), keeping the 9:00 -> 13:00 UTC assertion deterministic.
|
|
cls.task = cls.env['fusion.technician.task'].create({
|
|
'technician_id': cls.tech.id,
|
|
'scheduled_date': date(date.today().year + 1, 7, 1),
|
|
'time_start': 9.0,
|
|
'time_end': 10.0,
|
|
})
|
|
|
|
def test_local_to_utc_compute(self):
|
|
# 9:00 local Toronto (EDT, -4) -> 13:00 UTC stored
|
|
self.assertEqual(self.task.datetime_start.hour, 13)
|
|
|
|
def test_inverse_round_trips_with_same_tz(self):
|
|
# writing datetime_start back recovers the same local time_start
|
|
self.task.datetime_start = self.task.datetime_start # force inverse
|
|
self.task.flush_recordset(['datetime_start'])
|
|
self.assertAlmostEqual(self.task.time_start, 9.0, places=2)
|