From 3557fe124ad172ecd3727e31bf704f69dbca3390 Mon Sep 17 00:00:00 2001 From: Ravi Gohil Date: Wed, 29 Oct 2014 18:12:45 +0530 Subject: [PATCH] [FIX] fields: timezone aware context_timezone context_timestamp should always return a timezone aware timestamp, even when no timezone is set on the user. 7f88681 fixed the bug in old api fields (openerp/osv/fields.py) but it was not applied to new api fields (openerp/fields.py). opw 616612 --- openerp/fields.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openerp/fields.py b/openerp/fields.py index 14deaa8d601..036b5af82b9 100644 --- a/openerp/fields.py +++ b/openerp/fields.py @@ -1242,17 +1242,16 @@ class Datetime(Field): """ assert isinstance(timestamp, datetime), 'Datetime instance expected' tz_name = record._context.get('tz') or record.env.user.tz + utc_timestamp = pytz.utc.localize(timestamp, is_dst=False) # UTC = no DST if tz_name: try: - utc = pytz.timezone('UTC') context_tz = pytz.timezone(tz_name) - utc_timestamp = utc.localize(timestamp, is_dst=False) # UTC = no DST return utc_timestamp.astimezone(context_tz) except Exception: _logger.debug("failed to compute context/client-specific timestamp, " "using the UTC value", exc_info=True) - return timestamp + return utc_timestamp @staticmethod def from_string(value):