Odoo Help



aci aisha
on 2/7/15, 6:35 AM 748 views


In usual odoo selects the name field in many2one.

But how can i get other fields in many2one..(without using related)..

Eg:-I want to select the products in a new view of my custom module..



please provide example or describe more.

Emipro Technologies Pvt. Ltd.
on 2/7/15, 9:26 AM

Openies Services

--Openies Services--
Openies Services
| 2 2 4
Vadodara, India
--Openies Services--

We provide Odoo Services.

Contact us on : contact@openies.com

Openies Services
On 2/8/15, 2:23 AM


If you wanted to extend the search on the many2one field then you need to override the name_search method like 

def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
    return super(class_name, self).name_search(cr, uid, name, args=args, operator=operator, context=context, limit=limit)

It will return List of tuple, which is returned by name_get method.

In odoo name_get method is responsible to get name on the many2one field like [p123] Product 123

def name_get(self, cr, uid, ids, context=None):
    rerturn return super(class_name, self).name_get(cr, uid, ids, context=context)

Hope this helps in understanding name_search & name_get method in odoo.


Mohamed Essakali
On 2/7/15, 11:18 AM

You can change name_get and concatenate other fields. You can see example in addons.

For example if want to display field1 concatenated to field2 as "field1 / field2" in your many2one list use this code:

    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        reads = self.read(cr, uid, ids, ['field1', 'field2'], context)
        res = []
        for record in reads:
            field1 = record['field1']
            field2 = record['field2']
            if field2:
                name = field2 + ' / ' + field1
                name =  field1
            res.append((record['id'], name))
        return res

    def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
        if not args:
            args = []
        if not context:
            context = {}
        if name:
            # Be sure name_search is symetric to name_get
            name_splited = name.split(' / ')
            if len(name_splited) > 1:
                field1 = name_splited[1]
                field2 = name_splited[0]
                ids += self.search(cr, uid, [('field1', operator, field1),('field2', operator, field2)] + args, limit=limit, context=context)
                ids += self.search(cr, uid, ['|',('field1', operator, name),('field2', operator, name)] + args, limit=limit, context=context)
            ids = self.search(cr, uid, args, limit=limit, context=context)
        return self.name_get(cr, uid, ids, context)

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: 2/7/15, 6:35 AM
Seen: 748 times
Last updated: 3/30/15, 10:57 AM