Odoo Help

Welcome!

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.

0

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

By
Odooveloper (by Rui Franco)
on 3/10/15, 2:05 PM 522 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?

0

Cyril Gaspard (GEM)

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

Forum contributor since 2008

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

Hi,

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.

Bye

0

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.

-1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 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)

Stats

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