[FIX] hr_timesheet: allow leaves to be modified

- The HR staff may not be able to accept/refuse/cancel leaves if the
  module `project_timesheet_holidays` is installed.

  This is due to the commit c9da157149
  introducing a manual check on the current user's group without
  checking if the current environment is in superuser mode.

- Also fix the test verifying the access restriction, which meant to use
  a different user, but did that with sudo(), obviously defeating
  the fix. sudo is not used to switch user anymore, that `with_user`.

closes odoo/odoo#55274

X-original-commit: 75a166f1d115cc712bb39e7711d0fcb173732650
Related: odoo/enterprise#12149
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
This commit is contained in:
Toufik Ben Jaa
2020-07-31 15:36:02 +00:00
committed by Olivier Dony
parent 62f20bcad6
commit e7dcf6ac30
2 changed files with 3 additions and 4 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ class AccountAnalyticLine(models.Model):
def write(self, values):
# If it's a basic user then check if the timesheet is his own.
if not self.user_has_groups('hr_timesheet.group_hr_timesheet_approver') and any(self.env.user.id != analytic_line.user_id.id for analytic_line in self):
if not (self.user_has_groups('hr_timesheet.group_hr_timesheet_approver') or self.env.su) and any(self.env.user.id != analytic_line.user_id.id for analytic_line in self):
raise AccessError(_("You cannot access timesheets that are not yours."))
values = self._timesheet_preprocess(values)
+2 -3
View File
@@ -267,10 +267,9 @@ class TestTimesheet(TestCommonTimesheet):
})
timesheets = timesheet_1 + timesheet_2
# increase unit_amount to trigger amount recomputation
with self.assertRaises(AccessError):
# because the employee 1 is the sudo and he doesn't have the access right to update timesheet of employee 2
timesheets.sudo().write({
# should raise since employee 1 doesn't have the access rights to update employee's 2 timesheet
timesheets.with_user(self.empl_employee.user_id).write({
'unit_amount': 2,
})