[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
This commit is contained in:
parent
b28bfcdb3a
commit
3557fe124a
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue