[IMP] hr: use user data when creating an employee if available
This commit is contained in:
+11
-3
@@ -192,12 +192,20 @@ class Employee(models.Model):
|
||||
|
||||
@api.onchange('user_id')
|
||||
def _onchange_user(self):
|
||||
self.work_email = self.user_id.email
|
||||
self.name = self.user_id.name
|
||||
self.image = self.user_id.image
|
||||
if self.user_id:
|
||||
self.update(self._sync_user(self.user_id))
|
||||
|
||||
def _sync_user(self, user):
|
||||
return dict(
|
||||
name=user.name,
|
||||
image=user.image,
|
||||
work_email=user.email,
|
||||
)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('user_id'):
|
||||
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id'])))
|
||||
tools.image_resize_images(vals)
|
||||
return super(Employee, self).create(vals)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user