[MERGE]: merge with lp:~openerp-dev/openobject-addons/trunk-invitation_email_template-rma

bzr revid: aja@tinyerp.com-20130626131736-4gibdlpol5pdbhqs
This commit is contained in:
ajay javiya (OpenERP)
2013-06-26 18:47:36 +05:30
6 changed files with 148 additions and 124 deletions
+1
View File
@@ -21,5 +21,6 @@
import base_calendar
import crm_meeting
import service
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+3
View File
@@ -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,
+68 -124
View File
@@ -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 = """
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>%(name)s</title>
</head>
<body>
<table border="0" cellspacing="10" cellpadding="0" width="100%%"
style="font-family: Arial, Sans-serif; font-size: 14">
<tr>
<td width="100%%">Hello,</td>
</tr>
<tr>
<td width="100%%">You are invited for <i>%(company)s</i> Event.</td>
</tr>
<tr>
<td width="100%%">Below are the details of event. Hours and dates expressed in %(timezone)s time.</td>
</tr>
</table>
<table cellspacing="0" cellpadding="5" border="0" summary=""
style="width: 90%%; font-family: Arial, Sans-serif; border: 1px Solid #ccc; background-color: #f6f6f6">
<tr valign="center" align="center">
<td bgcolor="DFDFDF">
<h3>%(name)s</h3>
</td>
</tr>
<tr>
<td>
<table cellpadding="8" cellspacing="0" border="0"
style="font-size: 14" summary="Eventdetails" bgcolor="f6f6f6"
width="90%%">
<tr>
<td width="21%%">
<div><b>Start Date</b></div>
</td>
<td><b>:</b></td>
<td>%(start_date)s</td>
<td width="15%%">
<div><b>End Date</b></div>
</td>
<td><b>:</b></td>
<td width="25%%">%(end_date)s</td>
</tr>
<tr valign="top">
<td><b>Description</b></td>
<td><b>:</b></td>
<td colspan="3">%(description)s</td>
</tr>
<tr valign="top">
<td>
<div><b>Location</b></div>
</td>
<td><b>:</b></td>
<td colspan="3">%(location)s</td>
</tr>
<tr valign="top">
<td>
<div><b>Event Attendees</b></div>
</td>
<td><b>:</b></td>
<td colspan="3">
<div>
<div>%(attendees)s</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellspacing="10" cellpadding="0" width="100%%"
style="font-family: Arial, Sans-serif; font-size: 14">
<tr>
<td width="100%%">From:</td>
</tr>
<tr>
<td width="100%%">%(user)s</td>
</tr>
<tr valign="top">
<td width="100%%">-<font color="a7a7a7">-------------------------</font></td>
</tr>
<tr>
<td width="100%%"> <font color="a7a7a7">%(sign)s</font></td>
</tr>
</table>
</body>
</html>
"""
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 = '<br>'.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': '<br>'.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 = """<span style= "color:#A9A9A9; "> (<a href="%s">View Map</a>)</span>""" % 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):
@@ -135,4 +135,60 @@
<field eval="'(False,)'" name="args" />
</record>
</data>
<data>
<!--Email template -->
<record id="email_template_meeting_invitation" model="email.template">
<field name="name">Meeting Invitation</field>
<field name="email_from">${object.user_id.email or ''}</field>
<field name="subject">Meeting Invitation</field>
<field name="email_to" >${object.email}</field>
<field name="model_id" ref="base_calendar.model_calendar_attendee"/>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[<html><head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>%(name)s</title>
<style>
</style>
</head>
<body>
<table cellspacing="0" cellpadding="6" border="0" style = "margin: auto; display:block; border:2px solid #8E0000; background: #F8F8F8; border-radius: 2px; width: 600px; height: auto; ">
<tr>
<td style = "display: block; border: 2px solid #8E0000; height: 45px; width: auto; background : #8E0000; text-align: center; font-family: Arial, sans-serif; font-size: 20px; color:#FFFFFF; ">
<div style="text-align: center" > <b>%(name)s </b> </div> </td></tr>
<tr>
<td> <div style = " font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px" > <b> Hello %(user)s, </b> <br/>
%(organizer)s invited you for the %(name)s meeting of %(company)s. </div></td></tr>
<tr><td>
<table cellspacing="0" cellpadding="0" border="0" style="margin-top: 15px; margin-left: 10px; background: #F8F8F8">
<tr valign="top">
<td><div style = "height: 25px; width: 120px; background : # CCCCCC;font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;"><b> When :</b></div></td>
<td colspan="1"> <div style = " font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px" >%(time)s <span style= " color:#A9A9A9; "> (%(tz)s) </span></div>
</td> </tr>
<tr valign="top">
<td> <div style = "height: 25px; width: 120px; background : # CCCCCC; font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;"><b>Where :</b></div> </td>
<td colspan="1"> <div style = " font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px" >%(location)s %(map)s </div></td> </tr>
<tr valign="top">
<td> <div style = "height: 25px; width: 120px; background : # CCCCCC; font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;"><b>What :</b></div> </td>
<td colspan="3"> <div style = " font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px" >%(description)s</div> </td> </tr>
<tr valign="top">
<td style = "height: 25px;width: 120px; background : # CCCCCC; font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;"> <div><b>Attendees:<b></div> </td>
<td colspan="3"><div style = " font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 10px" > You, %(organizer)s <span style= "color:#A9A9A9; ont-size: 9px">- Organizer </br></span>%(attendees)s</div> </td> </tr>
</table></td></tr>
<tr >
<td><div style = " font-family: Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 10px" ><span style= "margin-top: 50px; margin-left: 200px;" ><a href="%(url)s">Accept</a> | <a href="%(url)s">Decline</a></span></div> </td>
<tr>
<td><div > -- </br> Sent by %(responsible)s from %(company)s.View this meeting detail <a href="%(url)s">directly in OpenERP</a></div> </td>
</tr>
</table>
</body>
</html>
]]></field>
</record>
</data>
</openerp>
+14
View File
@@ -0,0 +1,14 @@
import simplejson
import openerp.addons.web.http as oeweb
import openerp.addons.web.controllers.main as webmain
class crm_meetting_importstatus(oeweb.Controller):
_cp_path = '/meeting'
@oeweb.httprequest
def meeting_invitation(self, req, db='may_29'):
return webmain.html_template % {
'js': "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in webmain.manifest_list(req, 'js',db= db)),
'css': "\n ".join('<link rel="stylesheet" href="%s">' % i for i in webmain.manifest_list(req, 'css', db=db)),
'modules': simplejson.dumps(webmain.module_boot(req, db)),
'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body)); s.base_calendar.meeting_invitation();'
}
@@ -0,0 +1,6 @@
openerp.base_calendar = function(openerp) {
openerp.base_calendar.meeting_invitation = function(){
console.log("daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
};