Odoo Help

0

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

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

-1

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.

Register

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)

Stats

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