From 834e0bb36744a7baddeadd21f5360e32c0b22c93 Mon Sep 17 00:00:00 2001 From: Kersten Jeremy Date: Mon, 5 May 2014 12:46:11 +0200 Subject: [PATCH] [FIX] Calendar - set tz compatible in template mail and view (from email link). now it's possible to choose in template the TZ of the attendee, or the tz from event creator... bzr revid: jke@openerp.com-20140505104611-6qwpwwslxen0bea5 --- addons/calendar/calendar.py | 37 +++++++++++++++++++++++------ addons/calendar/calendar_data.xml | 2 +- addons/calendar/controllers/main.py | 10 +++++++- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index 0063b70811f..7f945726b2e 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -712,6 +712,24 @@ class calendar_event(osv.Model): return attendee return False + def get_date_formats(self, cr, uid, context): + lang = context.get("lang") + res_lang = self.pool.get('res.lang') + lang_params = {} + if lang: + ids = res_lang.search(request.cr, uid, [("code", "=", lang)]) + if ids: + lang_params = res_lang.read(request.cr, uid, ids[0], ["date_format", "time_format"]) + format_date = lang_params.get("date_format", '%B-%d-%Y') + format_time = lang_params.get("time_format", '%I-%M %p') + return (format_date, format_time) + + def get_display_time_tz(self, cr, uid, ids, tz=False, context=None): + if tz: + context["tz"] = tz + ev = self.browse(cr, uid, ids, context=context)[0] + return self._get_display_time(cr, uid, ev.zstart, ev.zstop, ev.duration, ev.allday, context=context) + def _get_display_time(self, cr, uid, zstart, zstop, zduration, zallday, context=None): """ Return date and time (from to from) based on duration with timezone in string : @@ -724,19 +742,22 @@ class calendar_event(osv.Model): tz = context.get('tz', False) if not tz: # tz can have a value False, so dont do it in the default value of get ! - tz = pytz.timezone('UTC') + context['tz'] = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz'] + tz = context['tz'] + format_date, format_time = self.get_date_formats(cr, uid, context=context) date = fields.datetime.context_timestamp(cr, uid, datetime.strptime(zstart, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context) date_deadline = fields.datetime.context_timestamp(cr, uid, datetime.strptime(zstop, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context) - event_date = date.strftime('%B-%d-%Y') - display_time = date.strftime('%H-%M') + event_date = date.strftime(format_date) + display_time = date.strftime(format_time) + if zallday: time = _("AllDay , %s") % (event_date) elif zduration < 24: duration = date + timedelta(hours=zduration) - time = ("%s at (%s To %s) (%s)") % (event_date, display_time, duration.strftime('%H-%M'), tz) + time = ("%s at (%s To %s) (%s)") % (event_date, display_time, duration.strftime(format_time), tz) else: - time = ("%s at %s To\n %s at %s (%s)") % (event_date, display_time, date_deadline.strftime('%B-%d-%Y'), date_deadline.strftime('%H-%M'), tz) + time = ("%s at %s To\n %s at %s (%s)") % (event_date, display_time, date_deadline.strftime(format_date), date_deadline.strftime(format_time), tz) return time def _compute(self, cr, uid, ids, fields, arg, context=None): @@ -1338,7 +1359,7 @@ class calendar_event(osv.Model): # Used for view in controller invitation = {'meeting': {}, 'attendee': []} - meeting = self.browse(cr, uid, int(meeting_id), context) + meeting = self.browse(cr, uid, int(meeting_id), context=context) invitation['meeting'] = { 'event': meeting.name, 'where': meeting.location, @@ -1364,7 +1385,8 @@ class calendar_event(osv.Model): elif interval == 'dayname': res = date.strftime('%A') elif interval == 'time': - res = date.strftime('%I:%M %p') + dummy, format_time = self.get_date_formats(cr, uid, context=context) + res = date.strftime(format_time) return res def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False): @@ -1711,6 +1733,7 @@ class ir_http(osv.AbstractModel): if error_message: raise BadRequest(error_message) + return True diff --git a/addons/calendar/calendar_data.xml b/addons/calendar/calendar_data.xml index e4e61018627..a56b6643eab 100644 --- a/addons/calendar/calendar_data.xml +++ b/addons/calendar/calendar_data.xml @@ -269,7 +269,7 @@
Dear ${object.cn} ,

The date of the meeting has been changed...
- The meeting created by ${object.event_id.user_id.partner_id.name} is now scheduled for : ${object.event_id.display_time}.

+ The meeting created by ${object.event_id.user_id.partner_id.name} is now scheduled for : ${object.event_id.get_display_time_tz(tz=object.partner_id.tz)}.

diff --git a/addons/calendar/controllers/main.py b/addons/calendar/controllers/main.py index 34710f57564..cb191912c8a 100644 --- a/addons/calendar/controllers/main.py +++ b/addons/calendar/controllers/main.py @@ -33,10 +33,18 @@ class meeting_invitation(http.Controller): registry = openerp.modules.registry.RegistryManager.get(db) meeting_pool = registry.get('calendar.event') attendee_pool = registry.get('calendar.attendee') + partner_pool = registry.get('res.partner') with registry.cursor() as cr: - attendee_data = meeting_pool.get_attendee(cr, openerp.SUPERUSER_ID, id) attendee = attendee_pool.search_read(cr, openerp.SUPERUSER_ID, [('access_token', '=', token)], []) + if attendee and attendee[0] and attendee[0].get('partner_id'): + partner_id = int(attendee[0].get('partner_id')[0]) + tz = partner_pool.read(cr, openerp.SUPERUSER_ID, partner_id, ['tz'])['tz'] + else: + tz = False + + attendee_data = meeting_pool.get_attendee(cr, openerp.SUPERUSER_ID, id, dict(tz=tz)) + if attendee: attendee_data['current_attendee'] = attendee[0]