diff --git a/addons/account/controllers/__init__.py b/addons/account/controllers/__init__.py index 903b755e71e..e5a6112c48f 100644 --- a/addons/account/controllers/__init__.py +++ b/addons/account/controllers/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import mail from . import portal diff --git a/addons/account/controllers/mail.py b/addons/account/controllers/mail.py new file mode 100644 index 00000000000..f30c69e21ba --- /dev/null +++ b/addons/account/controllers/mail.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import werkzeug + +from odoo.addons.mail.controllers.main import MailController +from odoo.exceptions import AccessError +from odoo.http import request +from odoo.tools.misc import consteq + + +class MailController(MailController): + + def _redirect_to_record(cls, model, res_id, access_token=None): + # If the current user doesn't have access to the invoice, but provided + # a valid access token, redirect him to the front-end view. + if model == 'account.invoice' and res_id and access_token: + uid = request.session.uid or request.env.ref('base.public_user').id + record_sudo = request.env[model].sudo().browse(res_id).exists() + try: + record_sudo.sudo(uid).check_access_rights('read') + record_sudo.sudo(uid).check_access_rule('read') + except AccessError: + if record_sudo.access_token and consteq(record_sudo.access_token, access_token): + record_action = record_sudo.with_context( + force_website=True).get_access_action(uid) + if record_action['type'] == 'ir.actions.act_url': + return werkzeug.utils.redirect(record_action['url']) + return super(MailController, cls)._redirect_to_record(model, res_id, access_token=access_token) diff --git a/addons/account/views/account_portal_templates.xml b/addons/account/views/account_portal_templates.xml index c4c7abc140e..fca47c3a50c 100644 --- a/addons/account/views/account_portal_templates.xml +++ b/addons/account/views/account_portal_templates.xml @@ -80,19 +80,10 @@ -
@@ -109,23 +100,25 @@