From 1bb30ecef0776c0f51f47c81ced3dcdd4a67596d Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Wed, 3 Feb 2010 16:16:24 +0530 Subject: [PATCH 1/2] [IMP]: caldav: Attendee Invitation improvement * Improved information+formating of mail to send on invitation * Implemented email gateway functions that updates attendees's response by mail reply bzr revid: rpa@openerp.co.in-20100203104624-hs3t7kk2966s90e4 --- addons/caldav/caldav.py | 132 +++++++++++++++++++++++++++------- addons/caldav/caldav_view.xml | 19 ++--- 2 files changed, 114 insertions(+), 37 deletions(-) diff --git a/addons/caldav/caldav.py b/addons/caldav/caldav.py index 1e2aa15b77a..fa4b811fa2b 100644 --- a/addons/caldav/caldav.py +++ b/addons/caldav/caldav.py @@ -67,52 +67,106 @@ def _links_get(self, cr, uid, context={}): return [(r['object'], r['name']) for r in res] html_invitation = """ + %(name)s -
- - + +
+ + + + + + + + + +
Hello,
You are invited for OpenERP Event.
Below are the details of event :
+ + + + + +

%(name)s

- +
- - - + - + - - + + - + -
-
Start Date
+
+
Start Date
%(start_date)s -
End Date
+
: %(start_date)s +
End Date
%(end_date)s: %(end_date)s
Description%(description)sDescription: %(description)s
-
Location
+
Location
%(location)s: %(location)s
-
Event Attendees
+
Event Attendees
-
%(attendees)s
+
: %(attendees)s
""" +
Are you coming? +
    +
  • + YES +
  • + NO +
  • + MAYBE +
+
+ + + + + + + + + + + + + + + + + + + +
Note: If you are interested please reply this + mail and keep only your response from options YES, NO + and MAYBE.
From:
%(user)s
--------------------------
%(sign)s
+ + +""" class calendar_attendee(osv.osv): _name = 'calendar.attendee' @@ -253,6 +307,30 @@ request was delegated to"), _defaults = { 'state': lambda *x: 'needs-action', } + + response_re = response_re = re.compile("Are you coming\?.*(YES|NO|MAYBE).*", re.UNICODE) + + def msg_new(self, cr, uid, msg): + return False + + def msg_act_get(self, msg): + mailgate_obj = self.pool.get('mail.gateway') + body = mailgate_obj.msg_body_get(msg) + actions = {} + res = self.response_re.findall(body['body']) + if res: + actions['state'] = res[0] + return actions + + def msg_update(self, cr, uid, ids, msg, data={}, default_act='None'): + msg_actions = self.msg_act_get(msg) + if msg_actions.get('state'): + if msg_actions['state'] in ['YES','NO','MAYBE']: + mapping = {'YES': 'accepted', 'NO': 'declined', 'MAYBE': 'tentative'} + status = mapping[msg_actions['state']] + print 'Got response for invitation id: %s as %s' % (ids, status) + self.write(cr, uid, ids, {'state': status}) + return True def onchange_user_id(self, cr, uid, ids, user_id, *args, **argv): if not user_id: @@ -278,7 +356,7 @@ request was delegated to"), vals['cn'] = vals.get("cn") res = super(calendar_attendee, self).create(cr, uid, vals, context) return res - + calendar_attendee() class res_alarm(osv.osv): @@ -457,7 +535,7 @@ or contains the text to be used for display"""), %s """ % (alarm.name, alarm.trigger_date, alarm.description, \ - alarm.user_id.name, alarm.user_id.sign) + alarm.user_id.name, alarm.user_id.signature) mail_to = [alarm.user_id.address_id.email] for att in alarm.attendee_ids: mail_to.append(att.user_id.address_id.email) @@ -1113,23 +1191,27 @@ class invite_attendee_wizard(osv.osv_memory): vals.update({'email': datas['email']}) att_id = att_obj.create(cr, uid, vals) obj.write(cr, uid, res_obj.id, {'attendee_ids': [(4, att_id)]}) - - sub = '[OpenERP Invitation] %s' % (res_obj.name) + sign = res_obj.user_id and res_obj.user_id.signature or '' + sign = '
'.join(sign and sign.split('\n') or []) + sub = '[%d] %s' % (att_id, res_obj.name) body_vals = {'name': res_obj.name, 'start_date': res_obj.date, 'end_date': res_obj.date_deadline or None, 'description': res_obj.description, 'location': res_obj.location or '-', - 'attendees': '-' #Todo + 'attendees': '-', #Todo + 'user': res_obj.user_id and res_obj.user_id.name or 'OpenERP User', + 'sign': sign } body = html_invitation % body_vals mail_to = [datas['email']] tools.email_send( - res_obj.user_id.name, + tools.config.get('email_from',False), mail_to, sub, body, - subtype='html' + subtype='html', + reply_to=tools.config.get('email_from',False), ) elif type == 'partner': diff --git a/addons/caldav/caldav_view.xml b/addons/caldav/caldav_view.xml index 4d10b9529f5..2d3a59892c7 100644 --- a/addons/caldav/caldav_view.xml +++ b/addons/caldav/caldav_view.xml @@ -95,21 +95,16 @@