Skip to Content
Menu
This question has been flagged
2 Replies
2046 Views

Hello Community, I would like to make user  can only see his contact but admin can sell all contact.How can I do that. Please suggest me.Thanks you.

Avatar
Discard
Best Answer

Hello GGWP,

You can create a read access record rule for the res.partner model.

With the following domain : [('id', '=', user.partner_id.id)].

And assign that rule to a group of common users not your admin.

Hope it helps.


Avatar
Discard
Best Answer

Hello GGWP,

Please find below code it may help you,

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

Avatar
Discard

Step 1: xml Code

<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: py Code

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_name'):
domain += [('user_id', '=', self.env.user.id)]
# user_id is field whose string is Salesperson
return super(ResPartner, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit, order=order)

@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
if self.user_has_groups('module_name.group_name'):
if 'user_id' or 'parent_id' or 'country_id' in groupby:
domain += [('user_id', '=', self.env.user.id)]
return super(ResPartner, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby,

Related Posts Replies Views Activity
0
Mar 22
879
1
Mar 18
3319
0
Sep 22
856
2
Oct 24
1700
0
Mar 15
3117