Skip to Content
Menu
This question has been flagged
1 Reply
1026 Views

For my Odoo, I need to restrict the access to the contact module. I already created a user group which won't be able to access any contacts (even with the proper url, they'll get an access error for any contact). 

What I now need is a specific filter that they can access their own contact.

Anyone could help on how the record rule syntax should be structured?

Avatar
Discard

Hello Jan Fischer,

I also faced same issue and found one solution that's working for me. I hope it work's for you also. No need to write record rule for this.

Please try below steps:

Step 1:- Create New group, that is already created by you. By providing this group to the user will only able to see own contacts only.

<record id="group_id" model="res.groups">
<field name="name">User: Own Contacts Only</field>
<field name="category_id" ref="category_name"/>
</record>

Step 2:- Write Search method,
py file

from odoo import models

class ResPartner(models.Model):
_inherit = "res.partner"

def search(self, args, **kwargs):
"""
Write Search Method for Partner to filter own contacts only
"""
if self.env.user.has_group('module_name.group_id'):
args += [('user_id', '=', self.env.user.id)]
return super(ResPartner, self).search(args, **kwargs)

Note:- user_id is a field under Sales & Purchase tab in res.partner view and string is Salesperson.

Step 3:- Create User and provide User: Own Contacts Only access rights as well provide Salesperson at partner level. User Own Contacts Only is filtered based on Salesperson.

Best Answer
Hello Jan Fischer,

I also faced same issue and found one solution that's working for me. I hope it work's for you also. No need to write record rule for this.

Please try below steps:

Step 1:- Create New group, that is already created by you. By providing this group to the user will only able to see own contacts only.


User: Own Contacts Only



Step 2:- Write Search method,
py file

from odoo import models


class ResPartner(models.Model):
_inherit = "res.partner"


def search(self, args, **kwargs):
"""
Write Search Method for Partner to filter own contacts only
"""
if self.env.user.has_group('module_name.group_id'):
args += [('user_id', '=', self.env.user.id)]
return super(ResPartner, self).search(args, **kwargs)

Note:- user_id is a field under Sales & Purchase tab in res.partner view and string is Salesperson.

Step 3:- Create User and provide User: Own Contacts Only access rights as well provide Salesperson at partner level. User Own Contacts Only is filtered based on Salesperson.
Avatar
Discard
Related Posts Replies Views Activity
1
Nov 23
802
1
Jul 24
235
0
Jun 24
345
4
Dec 23
22033
1
Aug 22
1030