Skip to Content
Menu
This question has been flagged
5 Replies
6595 Views

Hi all,

I'm working with Odoo 10.

How can I get and update employees' image from user's image (if employee related to a user).

I saw that the _onchange_user even in hr.employee, the employee image will be set by user_id.image. But, if the user change their image, employee's image will not be updated.

How can I implement this?

Thank you,

Avatar
Discard
Author Best Answer

I found solution for this, create new fields for employee, relate to user_id.image

user_image = fields.Binary("Photo", related='user_id.image')

user_image_medium = fields.Binary("Photo", related='user_id.image_medium')

user_image_small = fields.Binary("Photo", related='user_id.image_small')

Avatar
Discard
Best Answer

Hello Vu Huynh,

Here, method _onchange_user() in hr.employee will call user will change so selected user's detail will set in hr record

If in user any detail update then it will not _onchange_user() method of hr.employee.

If you want to do that, you can add following method in hr.employee model :

class hr_employee(models.Model)
_inherit="hr.employee"
@api.multi @api.depends('user_id.image') def change_employee_image(self): for record in self: record.image = record.user_id.image
image=fields.Binary("Image",compute="change_employee_image",store=True)
Avatar
Discard
Author

Hello Emipro,

Where should we call this function?

I have updated my answer, we need override field of image

Author

Hi,

I tried this but when accessing the record.user_id.image

It return a string which is the size of image, not the binary data (e.g: '54 kB').

It's strange, while I debug the _onchange_user() function, the image is binary data.