From e794672dd20763e2e3668e2249ba45da17d1b03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 2 Jan 2013 13:59:02 +0100 Subject: [PATCH] [IMP] Notification emails: link in signature improved. If access to document: direct link to document. If no document or not access: link to portal. bzr revid: tde@openerp.com-20130102125902-xp3vcs1ay7oog1ke --- addons/portal/mail_mail.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/portal/mail_mail.py b/addons/portal/mail_mail.py index a18c71759f8..a6532bf482c 100644 --- a/addons/portal/mail_mail.py +++ b/addons/portal/mail_mail.py @@ -19,6 +19,9 @@ # ############################################################################## +from urllib import urlencode +from urlparse import urljoin + from openerp import SUPERUSER_ID from openerp.osv import osv from openerp.tools import append_content_to_html @@ -39,6 +42,26 @@ class mail_mail(osv.Model): if partner: context = dict(context or {}, signup_valid=True) partner = self.pool.get('res.partner').browse(cr, SUPERUSER_ID, partner.id, context=context) - text = _("""Access your personal documents through our Customer Portal""") % partner.signup_url + text = '' + # private message + if not mail.model or not mail.res_id: + text = _("""

Access your messages through our Customer Portal

""") % partner.signup_url + # partner is also an user: add a link if read access to the document + elif partner.user_ids and self.check_access_rights(cr, partner.user_ids[0].id, 'read', raise_exception=False): + related_user = partner.user_ids[0] + try: + self.check_access_rule(cr, related_user.id, [mail.res_id], 'read', context=context) + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') + url_params = { + 'model': mail.model, + 'id': mail.res_id, + } + url = urljoin(base_url, "?#%s" % (urlencode(url_params))) + text = _("""

Read this document directly in OpenERP

""") % url + except: # TODO: catch good exception + text = _("""

Access your messages through our Customer Portal

""") % partner.signup_url + # partner not user + else: + text = _("""

Access your messages through our Customer Portal

""") % partner.signup_url body = append_content_to_html(body, ("

%s

" % text), plaintext=False) return body