how to dynamically change selection field list with onchange event on another field

Asked by seyi ayeni

Hello everybody
Please im trying to change the list of dropdown content on a selection menu through an on change event on another field, my code snippet is as follows.

_columns = {
    'room_id':fields.selection(......,'Room Name'),
     .....
}

def on_change_checkout(self, cr, uid, ids, checkin, checkout):
        if not checkin:
           return {'value':{'room_id': False}}

        cr.execute("select .....")
        res = cr.fetchall()
        output = []
        for name,pid in res:
           output.append((pid,name))
        return {'value':{'room_id': output}}

This is not working, does anyone have an idea as to how to accomplish this or whether it is possible at all to dynamically do this for a selection field. Pls help

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
jerzyo (jerzyo) said :
#1

Which server version are you using?

On 09/06/2011 11:15 AM, seyi ayeni wrote:
> Question #170294 on OpenERP Server changed:
> https://answers.launchpad.net/openobject-server/+question/170294
>
> Description changed to:
> Hello everybody
> Please im trying to change the list of dropdown content on a selection menu through an on change event on another field, my code snippet is as follows.
>
> _columns = {
> 'room_id':fields.selection(......,'Room Name'),
> .....
> }
>
> def on_change_checkout(self, cr, uid, ids, checkin, checkout):
> if not checkin:
> return {'value':{'room_id': False}}
>
> cr.execute("select .....")
> res = cr.fetchall()
> output = []
> for name,pid in res:
> output.append((pid,name))
> return {'value':{'room_id': output}}
>
> This is not working, does anyone have an idea as to how to accomplish
> this or whether it is possible at all to dynamically do this for a
> selection field. Pls help
>

--
Pozdrawiam serdecznie,

Jerzy Orłowski

Lacan Technologies Group
Członek Zarządu ds. technologii
Al. Stanów Zjednoczonych 53
04-028 Warszawa
tel. +48 (22) 266 01 02
tel. +48 (22) 292 16 16
kom. 668 151 245
www.lacan.com.pl
www.erpsystems.com.pl
www.serwerownie.com

Lacan Technologies Sp. z o.o. Sąd Rejonowy dla m.st. Warszawy w Warszawie, XIII Wydział Gospodarczy Krajowego Rejestru Sądowego, KRS: 0000319673, NIP: 521-351-01-01

Kapitał zakładowy: 50.000 PLN

Revision history for this message
seyi ayeni (sheyispat) said :
#2

i am using version 6.0.3

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) said :
#3

Hi,

as far as I know, this is currently not possible. Your code uses a facility that allows you to change the value/domain of a field in the form view, or raise a warning. I do not think it can replace the choice of values of a selection field.

If you need a dynamic selection, I would convert the room_id field to a proper model and use a plain many2one field with the selection widget. In released versions of the OpenERP server, this widget does not honour a domain but there is preliminary code that you could have a look at. Alternatively, use the regular many2one widget if that is acceptable to you.

To get the domain working with the selection widget on a many2one field, you need to merge the branches mentioned in comment #9 (I have not tested this code, and it may only work with trunk code):

    https://answers.launchpad.net/openobject-client/+question/135048

You might need to create a function field on the new model with a search function ("fnct_search") that returns the result of your current on_change routine in terms of resource ids. The field would never have an actual value but you can then use this field in the domain to filter the selection.

Goodluck,
Stefan.

Can you help with this problem?

Provide an answer of your own, or ask seyi ayeni for more information if necessary.

To post a message you must log in.