Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2004 มุมมอง

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.
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 25
771
1
พ.ย. 23
1734
1
ก.ค. 24
1368
0
มิ.ย. 24
1319
4
ธ.ค. 23
23834