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.

0

When changing the value of this combobox, the data will show the other combobox in openerp

By
lam a bao
on 11/21/13, 5:12 AM 1,947 views

Hi everyone

I have two combobox_A and combobox_B .When i change value of combobox_A ,data will show combobox_B

How do I? can you hepl me ?

thanks

0
Vitap ramdevputra
On 11/21/13, 5:48 AM

Hello lam,

while creating model, you have to keep the column type of " combobox_B" as many2one(), and also in many2one you have to specify optional parameter "domain". Here is the example how to use domain.

_columns = { 'x_combobox_B' : fields.many2one('nameofmodule','B(caption)', domain="[('id','=',combobox_A_id)]")}

Hope it helps you..

0
wilson zauma
On 4/4/14, 5:53 PM

In my XML, put this field :

<field name="aux_almacen_orig" on_change="onchange_almacen_aux_id(aux_almacen_orig)" />

and my_file.py

def _buscar_shortname_alm(self, cr, uid, context=None):

        obj=self.pool.get('stock.location')
        #ids = obj.search(cr, uid, [('shortcut', '!=', False),('usage','in',('internal','production'))],
        #    order='shortcut') 
        ids = obj.search(cr, uid, [('shortcut', '!=', False)], order='shortcut') 
        #print "\n ---- demo con browse Ids ---------------------------\n",ids
        # devuelve lista [12, 11, 7, 21, 20]

        resultado = obj.read(cr, uid, ids, ['id','shortcut'], context)
        #print "\n ---- demo con browse resultado ---------------------------\n",resultado
        #devuelve Lista de diccionarios ejemplo: [{'id': 11, 'shortcut': u'Almacen Principal - Salida'}, {'id': 7, 'shortcut': u'Produccion'}]

        #convertimos a una lista de tuplas
        res = []
        for record in resultado:
            #creamos la tupla interna
            rec = []
            #convertimos a cadena el ID para crear la tupla
            rec.append(str(record['id']))
            rec.append(record['shortcut'])
            #agregamos a tupla final
            res.append(tuple(rec))
        #print "\n ---- demo con browse res ---------------------------\n",res
        # devuelve lista de tuplas : [('11', 'Almacen Principal - Salida'), ('7','Produccion')]
        return res

_columns = {
'aux_almacen_orig': fields.selection(_buscar_shortname_alm, type="char",store=True, method=True,size=256, required=True, string="Almacen Origen" ),
}

def onchange_almacen_aux_id(self, cr, uid, ids, location_id, context=None):
    global globa_id_almacen_origen
    values = {}
    #asigno la variable global a usar en los detalles de doc de venta y llenado automatico
    # convierto la cadena que es el index seleccionado a un entero
    globa_id_almacen_origen = int(location_id)
    #asignamos al campo XML [location_id] el valor del ID seleccionado - sincroniza el campo
    values['location_id'] = int(location_id)
    return {'value': values }

This works for me. and when i select in combo one, automaty select the same in combo two. i wait for your commets.

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)

Stats

Asked: 11/21/13, 5:12 AM
Seen: 1947 times
Last updated: 3/16/15, 8:10 AM