[IMP] hr: make inheritable user fields to sync with employee

By enabling the method '_employee_values_sync' the original behavior is
keep. Furthermore, by overriding the method now is possible to decide
either a field is synced or not into employee.

closes odoo/odoo#96609

X-original-commit: 46c12cc0f72b2a6aba907fe903a255aed61a1695
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Francisco Alejandro González Luna
2022-07-27 03:35:14 +02:00
committed by Francisco Alejandro Gonzalez Luna
parent a6857f276a
commit 6c874fb297
+7 -1
View File
@@ -212,6 +212,11 @@ class User(models.Model):
self.env['hr.employee'].with_context(clean_context(self.env.context)).create(employee_create_vals)
return res
def _get_employee_fields_to_sync(self):
"""Get values to sync to the related employee when the User is changed.
"""
return ['name', 'email', 'image_1920', 'tz']
def write(self, vals):
"""
Synchronize user and its related employee
@@ -231,8 +236,9 @@ class User(models.Model):
result = super(User, self).write(vals)
employee_values = {}
for fname in [f for f in ['name', 'email', 'image_1920', 'tz'] if f in vals]:
for fname in [f for f in self._get_employee_fields_to_sync() if f in vals]:
employee_values[fname] = vals[fname]
if employee_values:
if 'email' in employee_values:
employee_values['work_email'] = employee_values.pop('email')