[FIX] resource : compute the correct default dates when planning a shift
Steps : - Install Planning - Users > Mitchell Admin > Preferences > Timezone : Europe/Brussels - Settings > Employees > Company Working Hours > Timezone : Japan - Planning > Gantt View > Week > Mitchell Admin x Friday > Click "+" button Issue : - Start date is set by default to Thursday 05:00 whereas it is expected to be set on Friday 00:00 Cause : - When we want to plan a shift on a day, we look into the 00:00 to 23:59 range for this day in calendar's tz to get the closest work time inside of it. - Yet, this doesn't take the "resource user" into account. Fix : - Set these limits for the day in resource's tz. opw-2678221 closes odoo/odoo#82555 X-original-commit: 1b248ebd58e0a57b070ebf7d67c6da78351a720a Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -629,12 +629,14 @@ class ResourceCalendar(models.Model):
|
||||
def interval_dt(interval):
|
||||
return interval[1 if match_end else 0]
|
||||
|
||||
tz = resource.tz if resource else self.tz
|
||||
if resource is None:
|
||||
resource = self.env['resource.resource']
|
||||
|
||||
if not dt.tzinfo or search_range and not (search_range[0].tzinfo and search_range[1].tzinfo):
|
||||
raise ValueError('Provided datetimes needs to be timezoned')
|
||||
dt = dt.astimezone(timezone(self.tz))
|
||||
|
||||
dt = dt.astimezone(timezone(tz))
|
||||
|
||||
if not search_range:
|
||||
range_start = dt + relativedelta(hour=0, minute=0, second=0)
|
||||
|
||||
@@ -533,6 +533,21 @@ class TestResMixin(TestResourceCommon):
|
||||
datetime_tz(2020, 4, 2, 18, 0, tzinfo='UTC')
|
||||
), "It should have found the start and end of the shift on the same day on April 2nd, 2020")
|
||||
|
||||
def test_adjust_calendar_timezone_before(self):
|
||||
# Calendar:
|
||||
# Every day 8-16
|
||||
self.jean.tz = 'Japan'
|
||||
self.calendar_jean.tz = 'Europe/Brussels'
|
||||
|
||||
result = self.jean._adjust_to_calendar(
|
||||
datetime_tz(2020, 4, 1, 0, 0, 0, tzinfo='Japan'),
|
||||
datetime_tz(2020, 4, 1, 23, 59, 59, tzinfo='Japan'),
|
||||
)
|
||||
self.assertEqual(result[self.jean], (
|
||||
datetime_tz(2020, 4, 1, 8, 0, 0, tzinfo='Japan'),
|
||||
datetime_tz(2020, 4, 1, 16, 0, 0, tzinfo='Japan'),
|
||||
), "It should have found a starting time the 1st")
|
||||
|
||||
def test_adjust_calendar_timezone_after(self):
|
||||
# Calendar:
|
||||
# Tuesdays 8-16
|
||||
|
||||
Reference in New Issue
Block a user