summaryrefslogtreecommitdiff
path: root/addons/resource/resource.py
diff options
context:
space:
mode:
authorGoffin Simon <sig@odoo.com>2015-09-03 11:13:16 +0200
committerGoffin Simon <sig@odoo.com>2015-09-04 10:01:20 +0200
commit64e1c28e358ec06a7683249fd7fae1ba631c1933 (patch)
tree62e1c8c77f786418f82ad61327856dddbce3add8 /addons/resource/resource.py
parenta69af9c908da34786f7b8267b79665d9540a033f (diff)
[FIX] resource: get_working_intervals_of_day
To compute start and end date of a working interval this function replaced hour in datetime object without taking into account the time zone. The start and end date taking respectively from calendar_working_day.hour_from and calendar_working_day.hour_to are in the time zone of the user and the datetime object are compared in UTC to avoid schedule's gap. This is why the start and end must be converted in UTC after being replaced by these hours. The tz_info must be removed from dates because it's forbidden to compare naive and aware dates. opw:648349
Diffstat (limited to 'addons/resource/resource.py')
-rw-r--r--addons/resource/resource.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/addons/resource/resource.py b/addons/resource/resource.py
index 67a287564e6..ca31366ba40 100644
--- a/addons/resource/resource.py
+++ b/addons/resource/resource.py
@@ -28,6 +28,7 @@ from openerp import tools
from openerp.osv import fields, osv
from openerp.tools.float_utils import float_compare
from openerp.tools.translate import _
+import pytz
class resource_calendar(osv.osv):
""" Calendar model for a resource. It has
@@ -335,11 +336,13 @@ class resource_calendar(osv.osv):
return intervals
working_intervals = []
+ tz_info = fields.datetime.context_timestamp(cr, uid, work_dt, context=context).tzinfo
for calendar_working_day in self.get_attendances_for_weekdays(cr, uid, id, [start_dt.weekday()], context):
- working_interval = (
- work_dt.replace(hour=int(calendar_working_day.hour_from)),
- work_dt.replace(hour=int(calendar_working_day.hour_to))
- )
+ x = work_dt.replace(hour=int(calendar_working_day.hour_from))
+ y = work_dt.replace(hour=int(calendar_working_day.hour_to))
+ x = x.replace(tzinfo=tz_info).astimezone(pytz.UTC).replace(tzinfo=None)
+ y = y.replace(tzinfo=tz_info).astimezone(pytz.UTC).replace(tzinfo=None)
+ working_interval = (x, y)
working_intervals += self.interval_remove_leaves(working_interval, work_limits)
# find leave intervals
@@ -598,7 +601,7 @@ class resource_calendar(osv.osv):
for dt_str, hours, calendar_id in date_and_hours_by_cal:
result = self.schedule_hours(
cr, uid, calendar_id, hours,
- day_dt=datetime.datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S').replace(minute=0, second=0),
+ day_dt=datetime.datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S').replace(second=0),
compute_leaves=True, resource_id=resource,
default_interval=(8, 16)
)