Odoo Help


How to define a domain for a field A depending on the ids of other field B in a view?

Alejandro Santana
on 1/14/15, 3:06 PM 962 views

In v8, I have a related Many2many field "A".

And I have a Many2one field "B".

Field B should only show the records available in A. (It is just to choose one record from A that will be default for other things)

How can I do this in a view, and having in mind A can change?




| 5 3 8
Delhi, India

Nothing to say .... :)

On 1/14/15, 3:34 PM

try this:

domain="[('id', 'in', many2many_field[0][2])]"

Thanks, Yogesh, this solved my problem. Two questions arise: What do the [0][2] mean? And where is it documented?

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/14/15, 4:20 PM

Anubia, I doubt if it is documented somewhere, but it works because m2m field is computed as list of a tuple containing ids of records on 2nd index of tuple eg [(0,0,[ids_of_records])], so field_name[0][2] extracts list of ids.

on 1/14/15, 8:34 PM

Hello, again. It is working for me in xml view file. But in python is not working. How do I get the ids from a One2many or Many2many in python code? Doing ids = myobject.one2many_field, fails. Doing ids = myobject.one2many_field[0][2] fails. Always complins about expecting singleton.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/22/15, 8:36 PM

line_ids = [] for line in one2many: line_ids.append(line.id) print "all ids of one2many record", line_ids # same way you can get for many2many

on 1/22/15, 8:50 PM

It fails anyway when I do "for line in one2many:". I have this: zone_ids = fields.One2many( comodel_name='base.zone', inverse_name='zip_ids', string='Zones', relation='base_zone_zip_rel', ) @api.one def get_zone_ids(self): ids = [] for rec in self.zone_ids: #

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/23/15, 10:37 AM

OK, solved, the problem was I was relating a One2many with a Many2many. Changed to be Many2many both and working perfectly.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/25/15, 1:02 PM

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: 1/14/15, 3:06 PM
Seen: 962 times
Last updated: 3/16/15, 8:10 AM