Odoo Help


How to apply domain filter on many2many field?

Stephen Raj
on 8/23/13, 9:16 AM 12,837 views


       I've created many2many field. I would like to apply domain filter on the many2many field. The field reference is not storing in the master table but it's creating another table and storing the reference ids. May I know how to apply the domain filter on the many2many field with an example.


http://forum.openerp.com/forum/topic23503.html (the page refers to v6 but that works on v7 as well)

on 8/23/13, 9:46 AM

I quote from the prakash link : " <field name="user_id" domain="[('id','in', [id for id in user_ids[0][2]]])]"/>

and you have to make the user_ids as a related field: 'user_ids': fields.related('group_id', 'user_ids', type="many2many", obj="res.users"),

and: the related field must be appear (at least invisible) in the form"

on 8/23/13, 12:58 PM
On 12/6/13, 12:09 PM

An example to solve your issue :

in the model :

'functions_ids': fields.many2many('functions', 'function_partner_rel', 'partner_id',
                                      'function_id', 'Functions'),
'function_id': fields.many2one('functions', 'Position Occupied'),

In the view:

<field name="function_id" readonly="False" domain="[('id', 'in', parent.functions_ids[0][2])]"/>

@el, could you explain [0][2] in the view?

Daniel Blanco
on 4/5/15, 9:41 AM

... and who is parent?

Daniel Blanco
on 4/5/15, 10:20 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/23/13, 9:16 AM
Seen: 12837 times
Last updated: 3/16/15, 8:10 AM