Odoo Help


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.


Getting a selection field based on a one2many field

on 10/1/13, 7:41 PM 1,257 views

I've 3 tables 'Adherant' , 'Affilie' and 'Depot' tables. I've 2 fields in my depot form view : adherant and affilie fields they are picked automatically from the corresponding tables. but what I want to do is that when I choose an adherant from the list, I do not want to have all affilie listed in the selection widget, because the affilie field is dependant on the adherant field.

How to get only a subset listed on affilie depending on the adherant field....? browse or name_search ORM methods ...?


AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 10/1/13, 10:48 PM

You can have a function define the list of possible items to select. There is an example of doing exactly this in the documentation of selection fields take a look in the developers manual.

On 10/2/13, 3:47 AM

Thank you for your answer, but the example i've seen :

def _get_selection(self, cursor, user_id, context=None):
return (
   ('choice1', 'This is the choice 1'),
   ('choice2', 'This is the choice 2'))

_columns = {

'sel' : fields.selection( _get_selection, 'What do you want ?') }

for example : the adherant list contains 3 people : Amine, Yassine, Karim and each one with its affilie list "one2many field"

Amine(Joe, Daniel, Michael) ; Yassine(Susan, Barbara, yoland) and Karim(Nadir, Nabil, Najm )

How to do the following dynamically :

When I choose Amine for example, I get only the 3 affilies Joe, Daniel, Michael on the second list to choose from; If I choose Yaasine on the adherant field, I should have only the 3 affilies Susan, Barbara, yoland instead of all the affilie that have been created in the affilie table.

I'm really stuck with this, because i do not know how to compare between the adherant name and the object got from the browse function

and how to put my code using the onchange function so that the choice of affilie depends dynamically on the adherant field

Thank you very much !

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

0 follower(s)


Asked: 10/1/13, 7:41 PM
Seen: 1257 times
Last updated: 3/16/15, 8:10 AM