diff --git a/addons/base_calendar/__init__.py b/addons/base_calendar/__init__.py
index b6447567083..a736d491b0e 100644
--- a/addons/base_calendar/__init__.py
+++ b/addons/base_calendar/__init__.py
@@ -21,5 +21,6 @@
import base_calendar
import crm_meeting
+import service
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/base_calendar/__openerp__.py b/addons/base_calendar/__openerp__.py
index 313ddb8453a..7d5b82a3cdf 100644
--- a/addons/base_calendar/__openerp__.py
+++ b/addons/base_calendar/__openerp__.py
@@ -47,6 +47,9 @@ If you need to manage your meetings, you should install the CRM module.
'base_calendar_data.xml',
'crm_meeting_data.xml',
],
+ 'js': [
+ 'static/src/js/*.js'
+ ],
'test' : ['test/base_calendar_test.yml'],
'installable': True,
'application': True,
diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py
index 896349ec5e6..cfb4fe7ba21 100644
--- a/addons/base_calendar/base_calendar.py
+++ b/addons/base_calendar/base_calendar.py
@@ -31,7 +31,8 @@ import time
from openerp import tools, SUPERUSER_ID
import openerp.service.report
-
+from urllib import urlencode
+from urlparse import urljoin
months = {
1: "January", 2: "February", 3: "March", 4: "April", \
5: "May", 6: "June", 7: "July", 8: "August", 9: "September", \
@@ -127,96 +128,6 @@ def _links_get(self, cr, uid, context=None):
res = obj.read(cr, uid, ids, ['object', 'name'], context=context)
return [(r['object'], r['name']) for r in res]
-html_invitation = """
-
-
-
-%(name)s
-
-
-
-
- | Hello, |
-
-
- | You are invited for %(company)s Event. |
-
-
- | Below are the details of event. Hours and dates expressed in %(timezone)s time. |
-
-
-
-
-
-
- %(name)s
- |
-
-
-
-
-
- |
- Start Date
- |
- : |
- %(start_date)s |
-
- End Date
- |
- : |
- %(end_date)s |
-
-
- | Description |
- : |
- %(description)s |
-
-
- |
- Location
- |
- : |
- %(location)s |
-
-
- |
- Event Attendees
- |
- : |
-
-
- |
-
-
- |
-
-
-
-
- | From: |
-
-
- | %(user)s |
-
-
- | -------------------------- |
-
-
- | %(sign)s |
-
-
-
-
-"""
-
class calendar_attendee(osv.osv):
"""
Calendar Attendee Information
@@ -493,6 +404,25 @@ property or property parameter."),
attendee_add.value = 'MAILTO:' + (attendee.email or '')
res = cal.serialize()
return res
+ def meeting_invitation(self, cr, uid, ids,context=None):
+ partner_obj = self.browse(cr,uid, ids,context=context)
+ for event_id in self.browse(cr, uid, ids, context):
+ event_id = event_id.ref.id
+ for partner in partner_obj:
+ if partner and partner.user_id:
+ related_user = partner.user_id
+ base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
+ query = {'db': cr.dbname}
+ fragment = {
+ 'login': related_user.login,
+ 'model': "crm.meeting",
+ 'view_type' : "form",
+ 'res_id': event_id,
+ }
+ url = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
+ else :
+ url = "https://openerp.my.openerp.com/#"
+ return url
def _send_mail(self, cr, uid, ids, mail_to, email_from=tools.config.get('email_from', False), context=None):
"""
@@ -502,50 +432,64 @@ property or property parameter."),
"""
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.name
for att in self.browse(cr, uid, ids, context=context):
- sign = att.sent_by_uid and att.sent_by_uid.signature or ''
- sign = '
'.join(sign and sign.split('\n') or [])
res_obj = att.ref
if res_obj:
- att_infos = []
+ att = {}
+ att_info = []
sub = res_obj.name
other_invitation_ids = self.search(cr, uid, [('ref', '=', res_obj._name + ',' + str(res_obj.id))])
for att2 in self.browse(cr, uid, other_invitation_ids):
- att_infos.append(((att2.user_id and att2.user_id.name) or \
- (att2.partner_id and att2.partner_id.name) or \
- att2.email) + ' - Status: ' + att2.state.title())
- #dates and times are gonna be expressed in `tz` time (local timezone of the `uid`)
+ att_info.append(att2.user_id and att2.user_id.name or att2.partner_id and att2.partner_id.name or att2.email)
+ att[att2.user_id and att2.user_id.name or att2.partner_id and att2.partner_id.name or att2.email] = att2.email
+
tz = context.get('tz', pytz.timezone('UTC'))
- #res_obj.date and res_obj.date_deadline are in UTC in database so we use context_timestamp() to transform them in the `tz` timezone
- date_start = fields.datetime.context_timestamp(cr, uid, datetime.strptime(res_obj.date, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
- date_stop = False
- if res_obj.date_deadline:
- date_stop = fields.datetime.context_timestamp(cr, uid, datetime.strptime(res_obj.date_deadline, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
- body_vals = {'name': res_obj.name,
- 'start_date': date_start,
- 'end_date': date_stop,
- 'timezone': tz,
- 'description': res_obj.description or '-',
- 'location': res_obj.location or '-',
- 'attendees': '
'.join(att_infos),
- 'user': res_obj.user_id and res_obj.user_id.name or 'OpenERP User',
- 'sign': sign,
- 'company': company
- }
- body = html_invitation % body_vals
- if mail_to and email_from:
- ics_file = self.get_ics_file(cr, uid, res_obj, context=context)
- vals = {'email_from': email_from,
- 'email_to': mail_to,
- 'state': 'outgoing',
- 'subject': sub,
- 'body_html': body,
- 'auto_delete': True}
+ allday = False
+ date = fields.datetime.context_timestamp(cr, uid, datetime.strptime(res_obj.date, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
+ date_deadline = fields.datetime.context_timestamp(cr, uid, datetime.strptime(res_obj.date_deadline, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
+ if res_obj.allday:
+ time = "AllDay" + "," + date.strftime('%B-%d-%Y')
+ tz = ''
+ elif res_obj.duration < 24:
+ duration = date + timedelta(hours= res_obj.duration)
+ time = date.strftime('%B-%d-%Y') + " at (" + date.strftime('%H-%M') + " To " + duration.strftime('%H-%M') + ")"
+ else :
+ time = date.strftime('%B-%d-%Y') + " at " + date.strftime('%H-%M') + " To \n" + date_deadline.strftime('%B-%d-%Y') + " at " + date_deadline.strftime('%H-%M')
+ footer = self.meeting_invitation(cr, uid, ids, context=context)
+ map = ''
+ if res_obj.location:
+ map_url = "http://maps.google.com/maps?oi=map&q=" + '+' + str(res_obj.location),
+ map = """ (View Map)""" % map_url
+ for user in att:
+ body_vals = {'user': user,
+ 'name': res_obj.name,
+ 'responsible': res_obj.user_id and res_obj.user_id.name or 'OpenERP User',
+ 'company': company,
+ 'description': res_obj.description or '-',
+ 'attendees': ', ' .join(att_info),
+ 'time': time,
+ 'tz': tz,
+ 'location': res_obj.location or '-',
+ 'map' : map or '',
+ 'organizer': res_obj.organizer,
+ 'url' : footer,
+ }
+ body_id = self.pool.get('email.template').search(cr, uid, [('subject', '=', 'Meeting Invitation')], context=context)
+ body = self.pool.get('email.template').browse(cr, uid, body_id[0], context=context).body_html % body_vals
+ if att[user] and email_from:
+ ics_file = self.get_ics_file(cr, uid, res_obj, context=context)
+ vals = {'email_from': email_from,
+ 'email_to': att[user],
+ 'state': 'outgoing',
+ 'subject': sub,
+ 'body_html': body,
+ 'auto_delete': True}
if ics_file:
vals['attachment_ids'] = [(0,0,{'name': 'invitation.ics',
'datas_fname': 'invitation.ics',
'datas': str(ics_file).encode('base64')})]
- self.pool.get('mail.mail').create(cr, uid, vals, context=context)
+ mail_id= self.pool.get('mail.mail').create(cr, uid, vals, context=context)
+ self.pool.get('mail.mail').send(cr, uid, [mail_id], context=context)
return True
def onchange_user_id(self, cr, uid, ids, user_id, *args, **argv):
diff --git a/addons/base_calendar/base_calendar_data.xml b/addons/base_calendar/base_calendar_data.xml
index 64aa7ba59b6..80ec77ba6e0 100644
--- a/addons/base_calendar/base_calendar_data.xml
+++ b/addons/base_calendar/base_calendar_data.xml
@@ -135,4 +135,60 @@
+
+
+
+ Meeting Invitation
+ ${object.user_id.email or ''}
+ Meeting Invitation
+ ${object.email}
+
+
+
+
+
+%(name)s
+
+
+
+
+
+ |
+ %(name)s |
+
+ | Hello %(user)s,
+ %(organizer)s invited you for the %(name)s meeting of %(company)s. |
+
+
+
+ When : |
+ %(time)s (%(tz)s)
+ |
+
+ | Where : |
+ %(location)s %(map)s |
+
+
+ | What : |
+ %(description)s |
+
+ | Attendees: |
+ You, %(organizer)s - Organizer %(attendees)s |
+ |
+
+ | |
+
+ | |
+
+
+
+
+