콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2836 화면

In Odoo every partner has a parent_id field. In my Odoo app I want to make that an user can only see his contacts (partners). That means that an user can only see those contacts in wich he is the parent contact. I created the following record rule for this purpose, but it is not working, the user can see all contacts, whether he is the parent or not. What am I doing wrong?

full example here : 

https://stackoverflow.com/questions/71739519/odoo-how-to-make-that-an-user-can-only-see-his-partners-through-parent-id-fiel

[('parent_id.id','=',user.partner_id.id)]

un my record rule i used the domanin force

아바타
취소
베스트 답변

Hello Ernesto Ruiz,

In the past, I had the similar problem and was able to solve it. Please see the steps below that may help you.

Find code in comment.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

아바타
취소

Step 1: Create Access right for Contact in security.xml file

<record model="ir.module.category" id="module_category_contact">
<field name="name">Contacts</field>
<field name="sequence">20</field>
<field name="parent_id" eval="False"/>
</record>

<record id="module_group_allow_contact_menu" model="ir.module.category">
<field name="name">Contacts</field>
<field name="parent_id" ref="module_category_contact"/>
</record>

<record id="group_allow_contact_menu_user" model="res.groups">
<field name="name">User: Own Documents Only</field>
<field name="category_id" ref="module_group_allow_contact_menu"/>
</record>

<record id="group_allow_contact_menu_admin" model="res.groups">
<field name="name">Administration</field>
<field name="category_id" ref="module_group_allow_contact_menu"/>
</record>

Step 2: Write below code into py file.
You may do this by using search_read method.
If you provide group_allow_contact_menu_user access rights to user then, that user can only see his partner.

from odoo import api, fields, models,

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

@api.model
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
if self.env.user.has_group('Module Name.group_allow_contact_menu_user'):
domain += [('user_id', '=', self.env.user.id)]
return super(ResPartner, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit, order=order)

관련 게시물 답글 화면 활동
0
7월 23
207
1
7월 19
4354
4
12월 23
23478
0
11월 19
4164
0
8월 19
3506