Odoo Help


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.


How Can I show parent child together in many2one field

on 3/10/14, 1:12 AM 1,845 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 4 7
Bikaner, India

OpenERP Devloper 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.

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)


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