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.


[SOLVED] How to change the way an employee's name is displayed?

Odooveloper (by Rui Franco)
on 3/10/15, 2:05 PM 513 views

Yes, I know all about name_get(). The thing is: hr.employee no longer uses a 'name' field. It get's the employee's name from resource.resource through the related_name field.  This means that name_get() won't work.

I've been asked to display the employee's name along with some other data that is part of the hr.employee model so, even if I changed resource.resource's name_get() I still wouldn't be able to show the employee's fields.

Has anyone come across such a problem?


Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/10/15, 5:57 PM


add a field 'name' or override existing field with type field you need function by example,

'name_related': fields.function(_get_name_you_need, type='char', string='Name', readonly=True, store=True),

add a store function in case the name in other object is changed, and an inverse function if you need to edit it.



Let me just make this matter clearer. The problem was that, in the employee tree view (as well as the Kanban), neither a "name", nor a "name_related" field were showing the values as I wanted them. However, the changes in the name_get did work, in the many2one fields.


So, I changed the name_get() function (as atchuthan suggested) and, then, I created a function field (as Cyril Gaspard (GEM) suggested).
Finally, in the tree view I put the new function field.


Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 3/11/15, 2:46 AM

You could use 'name_related' field available at HR module.

class hr_employee(orm.Model):
    _inherit = 'hr.employee'
    def name_get(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        if not ids:
            return []
        reads = self.read(cr, uid, ids, ['name_related','identification_id'], context=context)
        res = []
        for record in reads:
            name = record['name_related']
            if record['identification_id']:
                name = '[%s] %s' %(record['identification_id'], name)
            res.append((record['id'], name))
        return res  

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

1 follower(s)


Asked: 3/10/15, 2:05 PM
Seen: 513 times
Last updated: 3/16/15, 8:10 AM