From 6c874fb29754cefabf0d316c4b3baad5a10fb714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Alejandro=20Gonz=C3=A1lez=20Luna?= Date: Sat, 2 Jul 2022 02:11:18 +0000 Subject: [PATCH] [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 --- addons/hr/models/res_users.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/hr/models/res_users.py b/addons/hr/models/res_users.py index 9a51fbed6ce..e102b99ca8b 100644 --- a/addons/hr/models/res_users.py +++ b/addons/hr/models/res_users.py @@ -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')