From f16b194eaaaf2adea25b3f47aeee440b0b352332 Mon Sep 17 00:00:00 2001 From: yaih-odoo Date: Tue, 23 Jan 2024 13:05:40 +0000 Subject: [PATCH] [FIX] hr_expense: allow user access if manager To reproduce: - Create an employee record for the connected admin user - Switch the user's company to another one - Upgrade to 17.0 A user who has the correct rights can change his company anytime to see employees from other companies So it doesn't make sense to have access right error during an upgrade. In this line: https://github.com/odoo/odoo/blob/140e58c5a68db674fc1d240147e4d669b29f2cad/addons/hr_expense/models/hr_expense_sheet.py#L385 The call to parent_id.user_id fail upgrades to 17.0 if the parent and the user have different companies. Since Administrator-level users are not restricted, we put the check on that at the top to avoid errors during upgrades to 17.0. closes odoo/odoo#150660 Note: in 17.1, it was made possible to have a manager from another company: https://github.com/odoo/odoo/pull/112768/commits/b841a24fc11cb83ca8e95fce7a83648d87cb90e3 Signed-off-by: John Laterre (jol) --- addons/hr_expense/models/hr_expense_sheet.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/hr_expense/models/hr_expense_sheet.py b/addons/hr_expense/models/hr_expense_sheet.py index 865615cc59a..f40c960d9a3 100644 --- a/addons/hr_expense/models/hr_expense_sheet.py +++ b/addons/hr_expense/models/hr_expense_sheet.py @@ -392,6 +392,11 @@ class HrExpenseSheet(models.Model): sheet.is_editable = False continue + if is_hr_admin: + # Administrator-level users are not restricted + sheet.is_editable = True + continue + employee = sheet.employee_id is_own_sheet = employee.user_id == self.env.user @@ -407,11 +412,6 @@ class HrExpenseSheet(models.Model): # If Approver-level or designated manager, can edit other people sheet sheet.is_editable = True continue - - if is_hr_admin and sheet.state in {'draft', 'submit', 'approve'}: - # Administrator-level users are not restricted - sheet.is_editable = True - continue sheet.is_editable = False @api.constrains('expense_line_ids')