[FIX] resource: update default calendar timezone on first admin login (follow-up)

Steps to reproduce:
-------------------
1. Install the resource module without demo data (or install any module which depends on it, again without demo data).
2. Login with the administrator user for the first time.
3. The default resource calendar (e.g. "Standard 40 hours/week") timezone will be set to 'UTC' by default
while it should be set to the timezone of the administrator.

Fix:
-------------------
When there is no demo data, no resource_calendar_id is linked to the admin.
In this case, we need to retrieve the record of the default working calendar and
set its timezone to the one of the admin user on the first login.

This is a follow-up of this fix: https://github.com/odoo/odoo/pull/84258

task-3793313

closes odoo/odoo#162531

X-original-commit: b280a9b2c77a1a74a0154154cb4c1cf36e5111af
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Maxime de Neuville
2024-04-22 08:27:10 +00:00
parent f0172ad4b3
commit 1733122915
+4 -1
View File
@@ -19,6 +19,9 @@ class ResUsers(models.Model):
# If the timezone of the admin user gets set on their first login, also update the timezone of the default working calendar
if (vals.get('tz') and len(self) == 1 and not self.env.user.login_date
and self.env.user == self.env.ref('base.user_admin', False) and self == self.env.user):
self.resource_calendar_id.tz = vals['tz']
if self.resource_calendar_id:
self.resource_calendar_id.tz = vals['tz']
else:
self.env.ref('resource.resource_calendar_std', False).tz = vals['tz']
return rslt