Odoo Help


How to override name_get?

Rui Franco
on 9/4/13, 7:01 AM 4,778 views

I'm going mad with this one (or, perhaps, just going dumber):

I need to override the name_get method of project.task

It's not really important what I want to do (or if the code is clumsy), but to focus on this one annoying thing: the system totally ignores my function and it keeps calling the old (original) one.

Here's the code:

class project_task(osv.osv):
    _inherit = 'project.task'

    def name_get(self, cr, uid, ids, context=None):
            if context is None:
                context = {}

            if not ids:
                return []

            for r in self.read(cr, uid, ids, ['id', 'date_start', 'date_end', 'name'], context):
                if r['name']:

                aux=aux + ' ('

                if r['date_start']:
                    aux=aux + _(r['date_start'])

                aux=aux + ' - '

                if r['date_end']:
                    aux=aux + _(r['date_end'])

                aux=aux + ')'

            res=(r['id'], aux)

            super(project_task, self).name_get(cr, uid, ids, context=context)
            return aux


Why???? :)

Burhan Vakharia
On 1/30/16, 12:39 PM

Learn – Overriding name_get method in Odoo 8 with Example - Odoo Technical


very good article with screenshoots now i am following your blog.

on 8/24/16, 2:15 AM


name_get is a function which return list of pair. The pair is the id of the item and the name the item, example [(1, "SO001"), (4, "SO004")]. It is not a string.

The super method could be call if you think that the super method return the correct item's name else you don't call super.

def name_get(self, cr, uid, ids, context=None):
    if not ids:
        return []
    res = []
    for r in self.read(cr, uid, ids, ['id', 'date_start', 'date_end', 'name'], context):
        if r['name']:
            aux = r['name']
            aux = _(r['id'])  
            # why translate a random value? You can't define all the translation

         aux +=  " ("
         if r['date_start']:
             aux += _(r['date_start']) 
             # why translate a date? I think is a mistake, the _() function must have a 
             # known string, example _("the start date is %s") % r['date_start']

         aux +=  ' - '
         if r['date_end']:
             aux += _(r['date_end']) # same question

         aux += ')'

         # aux is the name items for the r['id']
         res.append((r['id'], aux))  # append add the tuple (r['id'], aux) in the list res

    return res

I hope my answer will be helpful

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: 9/4/13, 7:01 AM
Seen: 4778 times
Last updated: 1/30/16, 12:39 PM