[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) <lpe@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user