This question has been flagged
3 Replies
6200 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?

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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.

Avatar
Discard
Best Answer

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  

Avatar
Discard