This question has been flagged
4 Replies
8449 Views

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Author Best Answer

Thanks for post this answer Serpent Consulting services Pvt Ltd

Avatar
Discard