[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) <jol@odoo.com>
This commit is contained in:
yaih-odoo
2024-01-29 10:20:03 +00:00
parent 586f75687d
commit f16b194eaa
+5 -5
View File
@@ -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')