Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
9061 Weergaven

Hi to All,

I have to create an access rule in which I have to compare the company_id with Allowed Companies(many2many field company_ids in users screen).

Thanks in Advance

Avatar
Annuleer
Beste antwoord

Hi,
I have same case for Odoo V12. Following code works for me.
['|', ('x_users', '=', False),('x_users', 'in', [user.id])]
x_users is my many2many field.

Avatar
Annuleer
Beste antwoord

Here's another one:

[('company_id', 'in', user.read(['company_ids'])[0]['company_ids'])]

and yet another one (possibly slower, but shorter and nicer to read):

[('company_id', 'in', [c.id for c in user.company_ids])]

Avatar
Annuleer
Beste antwoord

Madhubabu,

In OpenERP, for major of the existing models the record rule exists where there is a field company_id or user_id.

If you model is custom, you should consider the following record rule.

['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]

=> Means the user will see the records of your model where he is the user of the main company or its children companies.

Or, foryour own record, its company_ids field for 'Allowed companies'. So [('company_id','in',user.company_ids)]

Hope this helps.

Thanks.

Avatar
Annuleer
Auteur Beste antwoord

Thanks for post this answer Serpent Consulting services Pvt Ltd

Avatar
Annuleer