Odoo Help


Is there a way to use a domain on a many2many field on openerp v6.1?

on 4/5/13, 5:42 AM 13,662 views


Is it a way to use domain on many2many field on openerp v6.1?

Here is my object : Code:

class user(osv.osv):

    'group_ids':fields.many2many('custom_module.group', 'custom_module_group_user_rel', 'user_id', 'group_id', 'Groups'), 

class group(osv.osv):

    'user_ids':fields.many2many('custom_module.group', 'custom_module_group_user_rel', 'group_id', 'user_id', 'Users'), 

I have added these fields on the views and it works fine. My problem is that I'd like to select only users who are in a specific group but I can't find the correct domain to apply.

Here is my view : Code:

<record ..>
<field name="name"/>
<field name="group_id"/>
<field name="user_id" domain="[('id','in', [group_id.user_ids]])]"/>

I would like that by selecting a group, the user could only select a user in this group.

Does somebody know what is wrong with my domain ? Or is it possible ?

Hi vivek, you found any solution? even i'm facing the same problem please help me out

Sam path
on 5/12/14, 3:23 AM

ClueLogics Technologies Pvt. Ltd.

--ClueLogics Technologies Pvt. Ltd.--
| 6 5 8
Delhi NCR, India
--ClueLogics Technologies Pvt. Ltd.--

 ClueLogics Technologies Pvt Ltd is a Software product and services provider. We are positioned to deliver robust, rapid and reliable Information Technology solutions that work. What we succeed upon is Technology and Technical Expertise. The industry review of ClueLogics has been commendable for the past years as most of its business comes from repeat orders by highly satisfied clients.

ClueLogics Technologies Pvt. Ltd.
On 7/9/15, 8:11 AM

Always use  in operator in domain if you seems need to check more then one such as many2many.

it shoud be domain="[('group_ids','in',[group_id])]"


Mohammad Alhashash

--Mohammad Alhashash--
| 5 5 8
Giza, Egypt
--Mohammad Alhashash--


Mohammad Alhashash
On 4/5/13, 6:04 AM

Try this

  <field name="user_id" domain="[('groupd_ids','=', group_id)]"/>

Hi Mohammad,

Thanks for your reply. Your suggestion does not work.

Please see the logic inside your filter

<field name="user_id" domain="[('groupd_ids','=', group_id)]"/>

[field name="user_id" domain="[([1,3,4],'=',[1])]

This does not work. Please suggest me something else.

instead of '=' operator, if you have something like 'group_ids','has','group_id', it can work. But we dont have any such operator.

please suggest me a work around to achieve this.

Thank you

on 4/5/13, 6:53 AM

Hi, i found a link : http://forum.openerp.com/forum/topic23503.html , but I am not able to use that. If you could give me a sample code, It would be great. Please do the needful

on 4/5/13, 6:55 AM

Actually x2many field handling in left-hand side of domains does not work as you think. You may have to quote the right-hand side ('group_id' instead of group_id). Check it and tell me the result.

Mohammad Alhashash
on 4/5/13, 7:58 AM

that is also not working. Please see this link and tell me if tat works. http://forum.openerp.com/forum/topic23503.html

on 4/5/13, 8:09 AM

Please somebody help me on this.. I am in a big trouble

on 4/5/13, 9:02 AM

My answer works in v7.0. I'm not sure about version 6.1. Sorry.

Mohammad Alhashash
on 4/5/13, 9:18 AM

It should work too in 6.1. Check the line: &lt;field name="stage_id" domain="section_id and [('section_ids', '=', section_id)] or []" /&gt; in addons/cr,/crm_lead_view.xml

Mohammad Alhashash
on 4/5/13, 9:26 AM
On 5/31/13, 9:15 AM

Hi Mohammad,

The answer you provided is the right one to filter based on many2many. I actually had the same domain filter in my code. But because of some redundancy of fields, it did not work.

Later I just removed the redundant fields and it worked like a charm.

so, The right answer is what you have suggested at first.

<field name="user_id" domain="[('groupd_ids','=', group_id)]"/>

Thanks for your support and sorry for the delay in updating the answer for my question.

You should not create a new answer for responding. Please read the FAQs. If the answer is correct, you should accept it and use the comment feature for response,

Mohammad Alhashash
on 6/1/13, 7:43 AM

Ok. I shall keep that in mind henceforth. Thanks

on 6/1/13, 8:54 AM
Gregor Heger
On 11/26/15, 2:55 PM

@Daniel Blankco

i know it is late, but in case somebody different reads this: function_id is located in the list view function_ids. Thereby, the scope of the domain lies within function_ids. So it it is not possible to address "function_ids" just by writing "function_ids[0][2]". The parent view, in which function_ids is located, has to be adressen. That is why parent. is for.
Entries in the function_ids list are represented by this list: [(6, 0, [1, 2, 3, 4])]. This is a so called x2many code. The ids of the function id fields is located in [1, 2, 3, 4]. So in order to address it, he writes parent.function_ids[0][2].
I don't really know why he is doing that.

On 9/22/14, 7:14 PM

try this

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

@namiri, saw this in another question and post. Could you pleas explain each term inside the domain? I understand that 'id' referes to "the id of function_id", but parent... who is parent in this case? and what [0][2] stands for? refers to the element of the many2one declaration?

Daniel Blanco
on 4/5/15, 10:37 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: 4/5/13, 5:42 AM
Seen: 13662 times
Last updated: 12/29/15, 6:55 AM