From 17331229153e27a5f108fd7e2845989ab0830db7 Mon Sep 17 00:00:00 2001 From: Maxime de Neuville Date: Wed, 13 Mar 2024 15:35:24 +0100 Subject: [PATCH] [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) --- addons/resource/models/res_users.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/resource/models/res_users.py b/addons/resource/models/res_users.py index 1ff3a822272..ef4f885919e 100644 --- a/addons/resource/models/res_users.py +++ b/addons/resource/models/res_users.py @@ -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