[FIX] resource: show planning resource in its timezone

Work hours in a planning do not respect the timezone

Steps to reproduce:
1. Set your computer timezone to 'America/New_York'
2. Install Manufacturing
3. Go to Settings > Manufacturing > Operations and enable Work Orders
4. Go to Settings > Technical > Resource > Working Times and open
   'Standard 40 hours/week' (San Francisco)
5. Edit the timezone to 'America/New_York'
6. Go to Manufacturing > Planning > Planning by Workcenter and trigger
   the day view
7. The work hours are not correct as they do not respect the timezone

Solution:
Add the timezone of the resource's calendar when computing
unavailabilities

opw-2903591

closes odoo/odoo#102066

X-original-commit: c7ac0ec29d69abdd5eda8887b6ec194db53419fd
Related: odoo/enterprise#32250
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
MerlinGuillaume
2022-10-04 16:01:19 +02:00
parent cd14193919
commit eeecb6f7c0
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -1046,7 +1046,7 @@ class ResourceResource(models.Model):
calendar_mapping[resource.calendar_id] |= resource
for calendar, resources in calendar_mapping.items():
resources_unavailable_intervals = calendar._unavailable_intervals_batch(start_datetime, end_datetime, resources)
resources_unavailable_intervals = calendar._unavailable_intervals_batch(start_datetime, end_datetime, resources, tz=timezone(calendar.tz))
resource_mapping.update(resources_unavailable_intervals)
return resource_mapping
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import date, datetime
from freezegun import freeze_time
from pytz import timezone, utc
from odoo import fields
@@ -1238,6 +1239,19 @@ class TestTimezones(TestResourceCommon):
(date(2018, 4, 13), 8),
])
@freeze_time("2022-09-21 15:30:00", tz_offset=-10)
def test_unavailable_intervals(self):
resource = self.env['resource.resource'].create({
'name': 'resource',
'tz': self.tz3,
})
intervals = resource._get_unavailable_intervals(datetime(2022, 9, 21), datetime(2022, 9, 22))
self.assertEqual(list(intervals.values())[0], [
(datetime(2022, 9, 21, 0, 0, tzinfo=utc), datetime(2022, 9, 21, 6, 0, tzinfo=utc)),
(datetime(2022, 9, 21, 10, 0, tzinfo=utc), datetime(2022, 9, 21, 11, 0, tzinfo=utc)),
(datetime(2022, 9, 21, 15, 0, tzinfo=utc), datetime(2022, 9, 22, 0, 0, tzinfo=utc)),
])
class TestResource(TestResourceCommon):
def test_calendars_validity_within_period(self):