From 97ad37439d1471cfbb4a682ab696d8d881b8f477 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 1 Feb 2019 11:10:17 +0000 Subject: [PATCH] [FIX] website_crm_partner_assign: portal url With a portal user, receive an email that says "Go to lead/opportunity" and click on the link The link's url is /mail/view which is the generic access controller Before this commit, the user is redirected to the backend, with fireworks of access errors After this commit, the portal url is opened As a side note, in master crm.lead should implement portal.mixin OPW 193509 closes odoo/odoo#30762 Signed-off-by: Lucas Perais (lpe) --- .../models/crm_lead.py | 34 ++++++++++++++++++- .../tests/test_partner_assign.py | 5 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/addons/website_crm_partner_assign/models/crm_lead.py b/addons/website_crm_partner_assign/models/crm_lead.py index 215b96e9457..3bb97901d9d 100644 --- a/addons/website_crm_partner_assign/models/crm_lead.py +++ b/addons/website_crm_partner_assign/models/crm_lead.py @@ -5,7 +5,7 @@ import random from odoo import api, fields, models, _ from odoo.addons.base_geolocalize.models.res_partner import geo_find, geo_query_address -from odoo.exceptions import AccessDenied +from odoo.exceptions import AccessDenied, AccessError class CrmLead(models.Model): _inherit = "crm.lead" @@ -270,3 +270,35 @@ class CrmLead(models.Model): return { 'id': lead.id } + + # + # DO NOT FORWARD PORT IN MASTER + # instead, crm.lead should implement portal.mixin + # + @api.multi + def get_access_action(self, access_uid=None): + """ Instead of the classic form view, redirect to the online document for + portal users or if force_website=True in the context. """ + self.ensure_one() + + user, record = self.env.user, self + if access_uid: + try: + record.check_access_rights('read') + record.check_access_rule("read") + except AccessError: + return super(CrmLead, self).get_access_action(access_uid) + user = self.env['res.users'].sudo().browse(access_uid) + record = self.sudo(user) + if user.share or self.env.context.get('force_website'): + try: + record.check_access_rights('read') + record.check_access_rule('read') + except AccessError: + pass + else: + return { + 'type': 'ir.actions.act_url', + 'url': '/my/opportunity/%s' % record.id, + } + return super(CrmLead, self).get_access_action(access_uid) diff --git a/addons/website_crm_partner_assign/tests/test_partner_assign.py b/addons/website_crm_partner_assign/tests/test_partner_assign.py index 1945e6bd2e4..137cd773c33 100644 --- a/addons/website_crm_partner_assign/tests/test_partner_assign.py +++ b/addons/website_crm_partner_assign/tests/test_partner_assign.py @@ -158,3 +158,8 @@ class TestPartnerLeadPortal(TestCrmCases): self.assertEqual(opportunity.team_id, salesmanteam, 'The created opportunity should have the same team as the salesman default team of the opportunity creator.') self.assertEqual(opportunity.partner_assigned_id, self.portal_partner, 'Assigned Partner of created opportunity is the (portal) creator.') + + def test_portal_mixin_url(self): + record_action = self.lead.get_access_action(self.portal_user.id) + self.assertEqual(record_action['url'], '/my/opportunity/%s' % self.lead.id) + self.assertEqual(record_action['type'], 'ir.actions.act_url')