Odoo Help


How to customize populating dropdown in OpenERP ?

on 6/26/13, 12:48 AM 3,647 views

Hi guys,

I am a newbie in OpenERP, now I have a task to customzie poplulating dropdown in OpenERP, specific task is displaying uom name + uom_category in dropdown instead of uom_name.

Example: field="uom_id"

The GUI currently display a dropdown just contain name of uom like below:


But now I would like to customize to see both uom name and uom category when user click on dropdow. Example:

Unit(s) - Unit
kg - Weight
g - Weight
cm- Length

Could we do that ? Because I saw openERP populating automatically and don't know how to custom it. I appreciate your help.

Many thanks, Duy.


Ghanshyam Prajapati

--Ghanshyam Prajapati--
Ghanshyam Prajapati
| 4 4 8
Pune, India
--Ghanshyam Prajapati--
OpenERP Developer
Ghanshyam Prajapati
On 6/26/13, 2:55 AM

Hi Duy,

First of all, you have to make one Custom module,

put following code in your .py file.

class product_uom(osv.osv):
    _inherit = 'product.uom'

def name_get(self, cr, uid, ids, context=None):
    res = []
    for rec in self.browse(cr, uid, ids, context):
        name = (rec.name ) + ' - ' + (rec.category_id and rec.category_id.name or '') 
        res.append((rec.id, name))
    return res

and in your .xml file,

use widget="selection" For example,

        <field name="uom_id" position="attributes">
            <attribute name="widget">selection</attribute>

Hope this work for you.

So useful, thank you!!

Michael O. Lambert
on 2/5/14, 10:43 AM
On 6/26/13, 3:31 AM

Hi all,

First, I would like to thank you for your very quick responses ( Keyur and Ghanshyam Prajapati ). Looks like the second solution that is what I need. But I have a question, why we don't write like below:

name = (rec.name ) + ' - ' + (rec.category_id.name)

I don't know why you get rec.category_id and rec.category_id.name or '') ? Why we need 'and' and 'or' operator while category_id.name is enough. Actually, I am still not familiar with query in OpenERP yet.

Thanks again, Duy.

In product.uom object category_id is required field, so you can use directly rec.category_id.name, but suppose if category_id is not required field then you can not use directly category_id.name because suppose you have not select any category_id, at that while you fetching name from category_id it gives you error because of category_id is null. please mark my answer if your problem is solved. thanks

Ghanshyam Prajapati
on 6/26/13, 3:54 AM

how can I mark your answer, vote it ? Because this is the first time I use this Q & A page. Thanks

on 6/26/13, 4:20 AM

Click on tick mark on my answer.

Ghanshyam Prajapati
on 6/26/13, 4:55 AM

I did. Thanks.

on 6/26/13, 6:08 AM
wilson zauma
On 3/21/14, 6:09 PM

I define in my class this way and works for me.

class stock_picking(osv.osv):
    _name = 'stock.picking' 
    _inherit = 'stock.picking'
    _columns = {
     'aux_almacen_orig': fields.selection(_buscar_shortname_alm,method="True", type="char", size=256, string="Almacen Origen" ),

then i define the function this way:

def _buscar_shortname_alm(self, cr, uid, context=None):
 obj = self.pool.get('stock.location')
        ids = obj.search(cr, uid, [])
        res = obj.read(cr, uid, ids, ['shortcut', 'id'], context)
        res = [(r['id'], r['shortcut']) for r in res if r['shortcut'] != False]
        return res

note: i define shorcut in my class stock location, this field only for to short the complete name in mi case, but you can change with another field that you have in your class:

class stock_location(osv.osv):
    _name = "stock.location"
    _inherit = "stock.location"
_columns = {
        'shortcut' :  fields.char('Nombre Corto',size=50),

and XML you show

<field name="aux_almacen_orig" />

and finally this is the result http://(w)(w)(w). orchidshouseperu.com/screenshots/Captura%20de%20pantalla%20de%202014-03-20%2015:52:20.png



| 4 4 8
Ahmedabad, India

Odoo Expert

On 6/26/13, 2:42 AM

Hi Duy,

Ofcourse you can customize your selection field. There is a method fields_get() of ORM.

This method gets all the description of fields. Once you have the description of the field you can easily customize it's functionality.

You can have little description of this method in ORM Documentation.

def fields_get(self, cr, uid, fields=None, context=None):
    res = super(your_class, self).fields_get(cr, uid, fields, context)
    if res['uom_id']:
    return res

Hope this solution solve your problem.


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 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: 6/26/13, 12:48 AM
Seen: 3647 times
Last updated: 3/16/15, 8:10 AM