From 104451bd56ee33d2a330afd4fc8f6801fae5d5bd Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 16 Apr 2014 17:44:50 +0200 Subject: [PATCH] [FIX] fields.date's date_to_datime function fixed bzr revid: qdp-launchpad@openerp.com-20140416154450-ws9w6wzf9s5kmjjj --- openerp/osv/fields.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index c4673305b43..439463b962a 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -344,27 +344,28 @@ class date(_column): exc_info=True) return (context_today or today).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) - def date_to_datetime(self, cr, uid, userdate, context=None): + @staticmethod + def date_to_datetime(model, cr, uid, userdate, context=None): """ Convert date values expressed in user's timezone to server-side UTC timestamp, assuming a default arbitrary time of 12:00 AM - because a time is needed. - + :param str userdate: date string in in user time zone :return: UTC datetime string for server-side use """ - user_date = datetime.strptime(userdate, DEFAULT_SERVER_DATE_FORMAT) + user_date = DT.datetime.strptime(userdate, tools.DEFAULT_SERVER_DATE_FORMAT) if context and context.get('tz'): tz_name = context['tz'] else: - tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz'] + tz_name = model.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz'] if tz_name: utc = pytz.timezone('UTC') context_tz = pytz.timezone(tz_name) - user_datetime = user_date + timedelta(hours=12.0) + user_datetime = user_date + DT.timedelta(hours=12.0) local_timestamp = context_tz.localize(user_datetime, is_dst=False) user_datetime = local_timestamp.astimezone(utc) - return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT) - return user_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + return user_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) + return user_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) class datetime(_column):