[IMP] mail_mail: delegated footer modification into a dedicated method called by send_get_email_body.

bzr revid: tde@openerp.com-20130315110421-if39vmvov4loe5u7
This commit is contained in:
Thibault Delavallée 2013-03-15 12:04:21 +01:00
parent cb6b598763
commit 646c83c250
2 changed files with 25 additions and 16 deletions

View File

@ -160,15 +160,12 @@ class mail_mail(osv.Model):
return 'Re: %s' % (mail.record_name)
return mail.subject
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
def send_get_mail_body_footer(self, cr, uid, mail, partner=None, context=None):
""" Return a specific footer for the ir_email body. The main purpose of this method
is to be inherited by Portal, to add modify the link for signing in, in
each notification email a partner receives.
:param browse_record mail: mail.mail browse_record
:param browse_record partner: specific recipient partner
"""
body = mail.body_html
body_footer = ""
# partner is a user, link to a related document (incentive to install portal)
if partner and partner.user_ids and mail.model and mail.res_id \
and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False):
@ -184,10 +181,23 @@ class mail_mail(osv.Model):
'id': mail.res_id,
}
url = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
text = _("""<small>Access this document <a href="%s">directly in OpenERP</a></small>""") % url
body = tools.append_content_to_html(body, ("<div><p>%s</p></div>" % text), plaintext=False, container_tag='div')
body_footer = _("""<small>Access this document <a style='color:inherit' href="%s">directly in OpenERP</a></small>""") % url
except except_orm, e:
pass
return body_footer
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 to add custom content depending on some module.
:param browse_record mail: mail.mail browse_record
:param browse_record partner: specific recipient partner
"""
body = mail.body_html
# add footer
body_footer = self.send_get_mail_body_footer(cr, uid, mail, partner=partner, context=context)
body = tools.append_content_to_html(body, body_footer, plaintext=False, container_tag='div')
return body
def send_get_mail_reply_to(self, cr, uid, mail, partner=None, context=None):

View File

@ -22,7 +22,6 @@
from openerp import SUPERUSER_ID
from openerp.osv import osv
from openerp.osv.orm import except_orm
from openerp.tools import append_content_to_html
from openerp.tools.translate import _
@ -30,18 +29,17 @@ class mail_mail(osv.Model):
""" Update of mail_mail class, to add the signin URL to notifications. """
_inherit = 'mail.mail'
def send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
def send_get_mail_body_footer(self, cr, uid, mail, partner=None, context=None):
""" add a signin link inside the body of a mail.mail
:param mail: mail.mail browse_record
:param partner: browse_record of the specific recipient partner
:return: the resulting body_html
"""
partner_obj = self.pool.get('res.partner')
body = mail.body_html
if partner:
contex_signup = dict(context or {}, signup_valid=True)
partner = partner_obj.browse(cr, SUPERUSER_ID, partner.id, context=contex_signup)
text = _("""<small>Access your messages and documents through <a href="%s">our Customer Portal</a></small>""") % partner.signup_url
body_footer = _("""<small>Access your messages and documents through <a style='color:inherit' href="%s">our Customer Portal</a></small>""") % partner.signup_url
# partner is an user: add a link to the document if read access
if partner.user_ids and mail.model and mail.res_id \
and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False):
@ -49,8 +47,9 @@ class mail_mail(osv.Model):
try:
self.pool.get(mail.model).check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context)
url = partner_obj._get_signup_url_for_action(cr, related_user.id, [partner.id], action='', res_id=mail.res_id, model=mail.model, context=context)[partner.id]
text = _("""<small>Access this document <a href="%s">directly in OpenERP</a></small>""") % url
text = _("""<small>Access this document <a style='color:inherit' href="%s">directly in OpenERP</a></small>""") % url
except except_orm, e:
pass
body = append_content_to_html(body, text, plaintext=False, container_tag='div')
return body
return body_footer
else:
return super(mail_mail, self).send_get_mail_body_footer(cr, uid, mail, partner=partner, context=context)