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

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

Avatar
Discard
Best Answer

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

Avatar
Discard

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)

Related Posts Replies Views Activity
0
Jul 23
207
1
Jul 19
3596
4
Dec 23
22035
0
Nov 19
3263
0
Aug 19
2965