[IMP] Portal: override of mail_mail to add the signin link into footer of send notifications.

bzr revid: tde@openerp.com-20120912155300-8ilg2g24yl7qsjfg
This commit is contained in:
Thibault Delavallée
2012-09-12 17:53:00 +02:00
parent 2b7112d7ae
commit 30fb693c20
3 changed files with 58 additions and 7 deletions
+7 -7
View File
@@ -137,7 +137,7 @@ class mail_mail(osv.Model):
mail.unlink()
return True
def _send_get_mail_subject(self, cr, uid, mail, force=False, partner=None, context=None):
def send_get_mail_subject(self, cr, uid, mail, force=False, partner=None, context=None):
""" if void and related document: '<Author> posted on <Resource>'
:param force: force the 'Author posted'... subject
@@ -148,7 +148,7 @@ class mail_mail(osv.Model):
return '%s posted on %s' % (mail.author_id.name, mail.record_name)
return mail.subject
def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
def send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
""" Return a specific ir_email body. The main purpose of this method
is to be inherited by Portal, to add a link for signing in, in
each notification email a partner receives.
@@ -158,15 +158,15 @@ class mail_mail(osv.Model):
"""
return mail.body_html
def _send_get_ir_email_dict(self, cr, uid, mail, partner=None, context=None):
def send_get_ir_email_dict(self, cr, uid, mail, partner=None, context=None):
""" Return a dictionary for specific ir_email values, depending on a
partner, or generic to the whole recipients given by mail.email_to.
:param mail: mail.mail browse_record
:param partner: browse_record of the specific recipient partner
"""
body = self._send_get_mail_body(cr, uid, mail, partner=partner, context=context)
subject = self._send_get_mail_subject(cr, uid, mail, partner=partner, context=context)
body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context)
subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context)
body_alternative = tools.html2plaintext(body)
email_to = [partner.email] if partner else tools.email_split(mail.email_to)
return {
@@ -200,9 +200,9 @@ class mail_mail(osv.Model):
ir_email_list = []
if notifier_ids:
for partner in self.pool.get('res.partner').browse(cr, uid, notifier_ids, context=context):
ir_email_list.append(self._send_get_ir_email_dict(cr, uid, mail, partner=partner, context=context))
ir_email_list.append(self.send_get_ir_email_dict(cr, uid, mail, partner=partner, context=context))
else:
ir_email_list.append(self._send_get_ir_email_dict(cr, uid, mail, context=context))
ir_email_list.append(self.send_get_ir_email_dict(cr, uid, mail, context=context))
# build an RFC2822 email.message.Message object and send it without queuing
for ir_email in ir_email_list:
+1
View File
@@ -20,6 +20,7 @@
##############################################################################
import portal
import mail_mail
import wizard
+50
View File
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import tools
from osv import osv
class mail_mail_portal(osv.Model):
""" Update of mail_mail class, to add the signin URL to notifications.
"""
_name = 'mail.mail'
_inherit = ['mail.mail']
def _generate_portal_url(self, cr, uid, partner_id, portal_group_id, key, context=None):
""" . """
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='', context=context)
return base_url + '/login?action=signin&partner_id=%s&group=%s&key=%s' % (partner_id, portal_group_id, key)
def send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
""" Return a specific ir_email body. The main purpose of this method
is to be inherited by Portal, to add a link for signing in, in
each notification email a partner receives.
:param mail: mail.mail browse_record
:param partner: browse_record of the specific recipient partner
"""
if partner:
url = self._generate_portal_url(cr, uid, partner.id, 12, 1234, context=context)
body = tools.append_content_to_html(mail.body_html, url)
return body
else:
return super(mail_mail_portal, self).send_get_mail_body(cr, uid, mail, partner=partner, context=context)