Skip to content

Commit 88d0c49

Browse files
author
Philippe Wauthy
committed
[FIX] resource: timezone end before assigning search_range
The end datetime is not timezoned in _adjust_to_calendar before defining the search_range and using the _get_closest_work_time method. Since _get_closest_work_time will timezone the timestamp received to start searching, the search interval needs to refer to the same end timestamp to avoid erratic behaviors. Task-2628876 closes odoo#79049 X-original-commit: cbf0cb6 Related: odoo/enterprise#21915 Signed-off-by: Yannick Tivisse (yti) <[email protected]> Signed-off-by: Laurent Stukkens (ltu) <[email protected]>
1 parent fd2a6c9 commit 88d0c49

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

addons/resource/tests/common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def setUp(self):
5454
(0, 0, 0, '1', 'line_section', 10), (8, 16, 0, '1', False, 11), (7, 15, 2, '1', False, 12),
5555
(8, 16, 3, '1', False, 13), (10, 16, 4, '1', False, 14)], 'Europe/Brussels')
5656

57+
self.calendar_paul = self._define_calendar('Morning and evening shifts', sum([((2, 7, i), (10, 16, i)) for i in range(5)], ()), 'Brazil/DeNoronha')
58+
5759
# Employee is linked to a resource.resource via resource.mixin
5860
self.jean = self.env['resource.test'].create({
5961
'name': 'Jean',
@@ -71,3 +73,8 @@ def setUp(self):
7173
'name': 'Jules',
7274
'resource_calendar_id': self.calendar_jules.id,
7375
})
76+
77+
self.paul = self.env['resource.test'].create({
78+
'name': 'Paul',
79+
'resource_calendar_id': self.calendar_paul.id,
80+
})

addons/resource/tests/test_resource.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,16 @@ def test_adjust_calendar(self):
522522
datetime_tz(2020, 3, 31, 8, 0, 0, tzinfo=self.john.tz),
523523
datetime_tz(2020, 4, 3, 23, 0, 0, tzinfo=self.john.tz),
524524
)
525+
# It should find the start and end within the search range
526+
result = self.paul._adjust_to_calendar(
527+
datetime_tz(2020, 4, 2, 2, 0, 0, tzinfo='UTC'),
528+
datetime_tz(2020, 4, 3, 1, 59, 59, tzinfo='UTC'),
529+
)
530+
531+
self.assertEqual(result[self.paul], (
532+
datetime_tz(2020, 4, 2, 4, 0, tzinfo='UTC'),
533+
datetime_tz(2020, 4, 2, 18, 0, tzinfo='UTC')
534+
), "It should have found the start and end of the shift on the same day on April 2nd, 2020")
525535

526536
def test_adjust_calendar_timezone_after(self):
527537
# Calendar:

0 commit comments

Comments
 (0)