diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2020-05-27 11:44:38 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2020-06-24 12:35:11 +0000 |
| commit | 103feca347321f36627c556569fa5377e7980fb9 (patch) | |
| tree | 1d859954eacad0d04c325a1e9582fad2b72bb98c /addons/resource/tests | |
| parent | 852594473dafefa592c5bf94ecda1066edcdb18e (diff) | |
[FIX] resource: Find intervals in the resource timezone
With a user with timezone "Europe/Brussels", add a
slot on the gantt view where the preceding day is a working day.
The default starting time will be the previous day.
Reason: the default starting time is midnight, adjusted to
the closest attendance interval in the employee's calendar.
However, midnight in "Europe/Brussels" is actually 10pm UTC
the previous day.
The method adjusting the datetime to the closest attendance only
checks within the corresponding day.
Two ways to fix this:
1) the business code calling `_adjust_to_calendar` should
timezone the datetimes itself. To avoid similar bugs in the future,
the method should be modified to only accept timezoned datetimes.
2) Change `_adjust_to_calendar` to convert datetimes it was given
to the resource's timezone and consider the dates in those converted
datetimes.
Option 2 is chosen because it seems to take care of the problem at a lower
level which allows the business code to not think about those timezone details.
While this is technically an API change (in a stable release), the method was
introduced recently by b058ca1 as a fix for an already broken method.
closes odoo/odoo#53582
X-original-commit: c6cecac60360a1d8b0c62ee155a818a3a28505e1
Related: odoo/enterprise#11399
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/resource/tests')
| -rw-r--r-- | addons/resource/tests/test_resource.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/addons/resource/tests/test_resource.py b/addons/resource/tests/test_resource.py index 123648855be..280447adf57 100644 --- a/addons/resource/tests/test_resource.py +++ b/addons/resource/tests/test_resource.py @@ -438,6 +438,10 @@ class TestCalendar(TestResourceCommon): calendar_dt = self.calendar_john._get_closest_work_time(dt, resource=self.john.resource_id) self.assertEqual(calendar_dt, start, "It should have taken john's specific attendances") + dt = datetime_tz(2020, 4, 4, 1, 0, 0, tzinfo='UTC') # The next day in UTC, but still the 3rd in john's timezone (America/Los_Angeles) + start = datetime_tz(2020, 4, 3, 16, 0, 0, tzinfo=self.john.tz) + calendar_dt = self.calendar_john._get_closest_work_time(dt, resource=self.john.resource_id) + self.assertEqual(calendar_dt, start, "It should have found the attendance on the 3rd April") class TestResMixin(TestResourceCommon): @@ -487,6 +491,21 @@ class TestResMixin(TestResourceCommon): datetime_tz(2020, 4, 3, 13, 0, 0, tzinfo=self.john.tz), )) + def test_adjust_calendar_timezone_after(self): + # Calendar: + # Tuesdays 8-16 + # Fridays 8-13 and 16-23 + tz = 'Europe/Brussels' + self.john.tz = tz + result = self.john._adjust_to_calendar( + datetime(2020, 4, 2, 23, 0, 0), # The previous day in UTC, but the 3rd in Europe/Brussels + datetime(2020, 4, 3, 20, 0, 0), + ) + self.assertEqual(result[self.john], ( + datetime(2020, 4, 3, 6, 0, 0), + datetime(2020, 4, 3, 21, 0, 0), + ), "It should have found a starting time the 3rd") + def test_work_days_data(self): # Looking at Jean's calendar |
