Odoo Help


How Can I show parent child together in many2one field

on 3/10/14, 1:12 AM 2,803 views

How Can I show parent child together in many2one field lookup. For example product by category tree

Override "name_get" method and many2one field shows product- Category. similar name_get example in the core module product/product.py available.

on 3/10/14, 1:31 AM

Thanks for the response. Can you please elaborate more how to override many2one field. For example i want to show something like below. parent -->child <newline> ->child2

on 3/11/14, 1:33 AM



| 5 5 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 3/13/14, 8:23 AM

I will explain with default openerp core module addons\product\product.py

1) In Product screen category many2one fields display with Category Name/ Parent Category Name

Based on this output Category name_get overridden

class product_category(osv.osv):

def name_get(self, cr, uid, ids, context=None):
    if isinstance(ids, (list, tuple)) and not len(ids):
        return []
    if isinstance(ids, (long, int)):
        ids = [ids]
    reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
    res = []
    for record in reads:
        name = record['name']
        if record['parent_id']:
            name = record['parent_id'][1]+' / '+name
        res.append((record['id'], name))
    return res

2) In Sale/Purchase order Product many2one fields display with [Product code] Product Name Based on this output Product name_get overridden

 _name = "product.product"

  def name_get(self, cr, user, ids, context=None):
        if context is None:
            context = {}
        if isinstance(ids, (int, long)):
            ids = [ids]
        if not len(ids):
            return []
        def _name_get(d):
            name = d.get('name','')
            code = d.get('default_code',False)
            if code:
                name = '[%s] %s' % (code,name)
            if d.get('variants'):
                name = name + ' - %s' % (d['variants'],)
            return (d['id'], name)

Hope this will help based on your requirement override name_get method.

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

0 follower(s)


Asked: 3/10/14, 1:12 AM
Seen: 2803 times
Last updated: 3/16/15, 8:10 AM