[IMP] hr: Sync some data between user and employee
Purpose of the task is to improve the employee image and phone behaviour while changing the user. So in this commit, IF there is no pitcure on employee then apply the image of user while adding the user to employee from cretae, write and onchage. do not change the employee image if employee image is already set while creating employee or changing the user on employee. Also improve the phone behaviour when changing the company, - Never change the mobile_phone when switching the company on employee - Always change the work_phone when switching the company, except if empty on res.company. closes odoo/odoo#50115 Taskid: 2240167 Closes: #50115 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
committed by
Yannick Tivisse
parent
3ad85b6f06
commit
999507007e
@@ -195,7 +195,7 @@ class HrEmployeePrivate(models.Model):
|
||||
@api.onchange('user_id')
|
||||
def _onchange_user(self):
|
||||
if self.user_id:
|
||||
self.update(self._sync_user(self.user_id))
|
||||
self.update(self._sync_user(self.user_id, bool(self.image_1920)))
|
||||
if not self.name:
|
||||
self.name = self.user_id.name
|
||||
|
||||
@@ -204,12 +204,13 @@ class HrEmployeePrivate(models.Model):
|
||||
if self.resource_calendar_id and not self.tz:
|
||||
self.tz = self.resource_calendar_id.tz
|
||||
|
||||
def _sync_user(self, user):
|
||||
def _sync_user(self, user, employee_has_image=False):
|
||||
vals = dict(
|
||||
image_1920=user.image_1920,
|
||||
work_email=user.email,
|
||||
user_id=user.id,
|
||||
)
|
||||
if not employee_has_image:
|
||||
vals['image_1920'] = user.image_1920
|
||||
if user.tz:
|
||||
vals['tz'] = user.tz
|
||||
return vals
|
||||
@@ -218,7 +219,7 @@ class HrEmployeePrivate(models.Model):
|
||||
def create(self, vals):
|
||||
if vals.get('user_id'):
|
||||
user = self.env['res.users'].browse(vals['user_id'])
|
||||
vals.update(self._sync_user(user))
|
||||
vals.update(self._sync_user(user, vals.get('image_1920') == self._default_image()))
|
||||
vals['name'] = vals.get('name', user.name)
|
||||
employee = super(HrEmployeePrivate, self).create(vals)
|
||||
url = '/web#%s' % url_encode({'action': 'hr.plan_wizard_action', 'active_id': employee.id, 'active_model': 'hr.employee'})
|
||||
@@ -235,7 +236,8 @@ class HrEmployeePrivate(models.Model):
|
||||
if account_id:
|
||||
self.env['res.partner.bank'].browse(account_id).partner_id = vals['address_home_id']
|
||||
if vals.get('user_id'):
|
||||
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id'])))
|
||||
# Update the profile pictures with user, except if provided
|
||||
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id']), bool(vals.get('image_1920'))))
|
||||
res = super(HrEmployeePrivate, self).write(vals)
|
||||
if vals.get('department_id') or vals.get('user_id'):
|
||||
department_id = vals['department_id'] if vals.get('department_id') else self[:1].department_id.id
|
||||
|
||||
@@ -101,8 +101,8 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
@api.depends('address_id')
|
||||
def _compute_phones(self):
|
||||
for employee in self.filtered('address_id'):
|
||||
employee.work_phone = employee.address_id.phone
|
||||
employee.mobile_phone = employee.address_id.mobile
|
||||
if employee.address_id.phone:
|
||||
employee.work_phone = employee.address_id.phone
|
||||
|
||||
@api.depends('company_id')
|
||||
def _compute_address_id(self):
|
||||
|
||||
Reference in New Issue
Block a user