Skip to content
Snippets Groups Projects
Commit 85ab51c7 authored by Thomas Lefebvre (thle)'s avatar Thomas Lefebvre (thle)
Browse files

[FIX] hr_employee: synchronise if user is removed


Steps to reproduce:
-------------------
- create two employees (A and B);
- create a user;
- add the user in Related User of employee A;
- remove the user;
- add the user in Related User of employee B;
- change the Work Email of the employee B.

Issue:
------
The Work Email of the employee A is also updated.

Cause:
------
When we add a `user_id` to an employee,
we update the `work_contact_id` field.
Fields `mobile_phone` and `work_email` are inverse fields.
When we modify them, the `_inverse_work_contact_details`
method is called.
We update the `work_contact_id` linked to the employee.

When we delete an employee's `user_id`,
we don't update the `work_contact_id`.
Therefore, when we update an employee's `work_contact_id`,
we call the `_compute_work_contact_details` method
method for all employees who have the same `work_contact_id`.

The result is that we modify the `mobile_phone` and `ẁork_email`
fields for all employees linked to the `work_contact_id`.

Solution:
---------
Differentiate the case where the `user_id` is `False` (>< `None`)
when it is modified and does not contain
a value to "synchronise" the `work_contact_id`.

opw-3338188

closes odoo/odoo#123830

Signed-off-by: default avatarKevin Baptiste <kba@odoo.com>
parent a4549981
Branches
Tags
No related merge requests found
......@@ -362,7 +362,7 @@ class HrEmployeePrivate(models.Model):
self.message_unsubscribe(self.address_home_id.ids)
if vals['address_home_id']:
self._message_subscribe([vals['address_home_id']])
if vals.get('user_id'):
if 'user_id' in vals:
# Update the profile pictures with user, except if provided
vals.update(self._sync_user(self.env['res.users'].browse(vals['user_id']),
(bool(self.image_1920))))
......
......@@ -181,3 +181,31 @@ class TestHrEmployee(TestHrCommon):
'partner_id': partner.id,
})
self.assertFalse(self.env['res.users'].search([('login', '=', 'test_user')]).employee_id)
def test_employee_update_work_contact_id(self):
"""
Check that the `work_contact_id` information is no longer
updated when an employee's `user_id` is removed.
"""
user = self.env['res.users'].create({
'name': 'Test',
'login': 'test',
'email': 'test@example.com',
})
employee_A, employee_B = self.env['hr.employee'].create([
{
'name': 'Employee A',
'user_id': user.id,
'work_email': 'employee_A@example.com',
},
{
'name': 'Employee B',
'user_id': False,
'work_email': 'employee_B@example.com',
}
])
employee_A.user_id = False
employee_B.user_id = user.id
employee_B.work_email = 'new_email@example.com'
self.assertEqual(employee_A.work_email, 'employee_A@example.com')
self.assertEqual(employee_B.work_email, 'new_email@example.com')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment