[IMP] hr: add default avatar of employee

Before this commit, when the user creates new resource and employee on
the fly in many2one field, the default avatar of Initial name should be
set instead of placeholder (grey icon). The reason why a grey icon is
displayed is because the `_compute_avatar` for employee set that icon
when avatar or image is not found.

This commit add default avatar of initial name when new resource and
employee is created.

task-3251689

closes odoo/odoo#123403

Related: odoo/enterprise#41823
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
ravb-odoo
2023-06-23 16:35:07 +02:00
parent b8f2579805
commit 16ed8d3141
+7 -5
View File
@@ -160,14 +160,16 @@ class HrEmployeePrivate(models.Model):
super()._compute_avatar_128()
def _compute_avatar(self, avatar_field, image_field):
employee_wo_user_or_image_ids = []
for employee in self:
if not (employee.user_id or employee._origin[image_field]):
employee_wo_user_or_image_ids.append(employee.id)
continue
avatar = employee._origin[image_field]
if not avatar:
if employee.user_id:
avatar = employee.user_id[avatar_field]
else:
avatar = base64.b64encode(employee._avatar_get_placeholder())
if not avatar and employee.user_id:
avatar = employee.user_id[avatar_field]
employee[avatar_field] = avatar
super(HrEmployeePrivate, self.browse(employee_wo_user_or_image_ids))._compute_avatar(avatar_field, image_field)
def action_create_user(self):
self.ensure_one()