Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2258 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất
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.
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 5 25
1184
1
thg 11 23
1966
1
thg 7 24
1658
0
thg 6 24
1569
4
thg 12 23
24253