As the survey hardcode lot's of views and reports in python, we do not beneficiate from automatic timezone conversions in the webclient.
Hopefully this is fixed in v8 after refactoring of the survey module. opw 608786
import time
+import pytz
+from datetime import datetime
from openerp import pooler, tools
from openerp.report import report_sxw
from openerp.report.interface import report_rml
class survey_browse_response(report_rml):
def create(self, cr, uid, ids, datas, context):
+ if context is None:
+ context = {}
_divide_columns_for_matrix = 0.7
_display_ans_in_rows = 5
_pageSize = ('29.7cm','21.1cm')
for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
tbl_width = float(_tbl_widths.replace('cm', ''))
colwidth = "2.5cm,4.8cm," + str(tbl_width - 15.0) +"cm,3.2cm,4.5cm"
- resp_create = tools.ustr(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S')))
+ timezone = pytz.timezone(context.get('tz') or 'UTC')
+ create_date = pytz.UTC.localize(datetime.strptime(response.date_create.split('.')[0], tools.DEFAULT_SERVER_DATETIME_FORMAT))
+ resp_create = create_date.astimezone(timezone).strftime("%Y-%m-%d %H:%M:%S") #Converting date to user's timezone
rml += """<blockTable colWidths='""" + colwidth + """' style="Table_heading">
<tr>
<td><para style="terp_default_9_Bold">""" + _('Print Date : ') + """</para></td>
##############################################################################
import copy
+import pytz
from datetime import datetime
from dateutil.relativedelta import relativedelta
from time import strftime
def name_get(self, cr, uid, ids, context=None):
if not len(ids):
return []
+ if context is None:
+ context = {}
reads = self.read(cr, uid, ids, ['user_id','date_create'], context=context)
res = []
for record in reads:
- name = (record['user_id'] and record['user_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')'
+ timezone = pytz.timezone(context.get('tz') or 'UTC')
+ create_date = pytz.UTC.localize(datetime.strptime(record['date_create'].split('.')[0], tools.DEFAULT_SERVER_DATETIME_FORMAT))
+ localized_create_date = create_date.astimezone(timezone)
+ name = (record['user_id'] and record['user_id'][1] or '' )+ ' (' + localized_create_date.strftime("%Y-%m-%d %H:%M:%S") + ')'
res.append((record['id'], name))
return res
##############################################################################
import base64
+import pytz
import datetime
from lxml import etree
import os
# TODO: l10n, cleanup this code to make it readable. Or template?
xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'})
record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']])
- etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(_('Answer Of :- ') + record.user_id.name + _(', Date :- ') + record.date_create.split('.')[0] )), 'align':"0.0"})
+ timezone = pytz.timezone(context.get('tz') or 'UTC')
+ response_date = pytz.UTC.localize(datetime.datetime.strptime(record['date_create'].split('.')[0], tools.DEFAULT_SERVER_DATETIME_FORMAT))
+ localized_response_date = response_date.astimezone(timezone)
+ etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(_('Answer Of :- ') + record.user_id.name + _(', Date :- ') + localized_response_date.strftime("%Y-%m-%d %H:%M:%S") )), 'align':"0.0"})
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(_(" Answer :- ") + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"})
if context.get('response_no',0) > 0:
etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"})