Odoo Help

Welcome!

This community 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.

2

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

By
Vivekrajan
on 4/5/13, 5:42 AM 10,441 views

Hello,

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

Here is my object : Code:

class user(osv.osv):

_columns={
    'group_ids':fields.many2many('custom_module.group', 'custom_module_group_user_rel', 'user_id', 'group_id', 'Groups'), 
}
user()

class group(osv.osv):

_columns={
    'user_ids':fields.many2many('custom_module.group', 'custom_module_group_user_rel', 'group_id', 'user_id', 'Users'), 
}
group()

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]])]"/>
...
</record>

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
2

Mohammad Alhashash

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

Developer

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

Vivekrajan
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

Vivekrajan
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

Vivekrajan
on 4/5/13, 8:09 AM

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

Vivekrajan
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
2
Vivekrajan
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

Vivekrajan
on 6/1/13, 8:54 AM
1

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
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])]"

0
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.

0
namiri
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/5/13, 5:42 AM
Seen: 10441 times
Last updated: 12/29/15, 6:55 AM