跳至内容
菜单
此问题已终结
1 回复
1970 查看

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?

形象
丢弃

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.

最佳答案
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.
形象
丢弃
相关帖文 回复 查看 活动
2
5月 25
729
1
11月 23
1695
1
7月 24
1329
0
6月 24
1286
4
12月 23
23786