Skip to content

Commit cbf0cb6

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#78990 X-original-commit: 36e20a3 Related: odoo/enterprise#21890 Signed-off-by: Yannick Tivisse (yti) <[email protected]> Signed-off-by: Laurent Stukkens (ltu) <[email protected]>
1 parent 6c5dfad commit cbf0cb6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

addons/resource/models/resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ def _adjust_to_calendar(self, start, end):
955955
search_range = None
956956
tz = timezone(resource.tz)
957957
if calendar_start and start.astimezone(tz).date() == end.astimezone(tz).date():
958+
end = end.astimezone(tz)
958959
# Make sure to only search end after start
959960
search_range = (
960961
start,

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@ def test_adjust_calendar(self):
505505
datetime_tz(2020, 4, 3, 13, 0, 0, tzinfo=self.john.tz),
506506
))
507507

508+
# It should find the start and end within the search range
509+
result = self.paul._adjust_to_calendar(
510+
datetime_tz(2020, 4, 2, 2, 0, 0, tzinfo='UTC'),
511+
datetime_tz(2020, 4, 3, 1, 59, 59, tzinfo='UTC'),
512+
)
513+
514+
self.assertEqual(result[self.paul], (
515+
datetime_tz(2020, 4, 2, 4, 0, tzinfo='UTC'),
516+
datetime_tz(2020, 4, 2, 18, 0, tzinfo='UTC')
517+
), "It should have found the start and end of the shift on the same day on April 2nd, 2020")
518+
508519
def test_adjust_calendar_timezone_after(self):
509520
# Calendar:
510521
# Tuesdays 8-16

0 commit comments

Comments
 (0)