Odoo Help


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

Rui Franco
on 3/10/15, 2:05 PM 853 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.


Rui Franco
On 3/11/15, 6:14 AM

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 5 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  

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: 3/10/15, 2:05 PM
Seen: 853 times
Last updated: 3/16/15, 8:10 AM