From 268025dccce6282f093aae432d104e2fe425463d Mon Sep 17 00:00:00 2001 From: Florian Damhaut Date: Thu, 24 Feb 2022 14:54:01 +0000 Subject: [PATCH] [FIX] hr_holidays: HR leave only approvable by time off officer Step to reproduce: - Create a time off type T with approval 'time off officer' - As user U create a time off request of type T - Login as the manager of U (which should not be a time off officer) - Approve the time off of U Current Behaviour: - Time off is approved Behaviour after PR: - Time off is not approved and an error is raised opw-2753845 closes odoo/odoo#85622 X-original-commit: 8a0564369baf9de7797a58ab0cd5cae870b910cf Signed-off-by: Kevin Baptiste Signed-off-by: Damhaut Florian (flda) --- addons/hr_holidays/i18n/hr_holidays.pot | 6 ++++++ addons/hr_holidays/models/hr_leave.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/addons/hr_holidays/i18n/hr_holidays.pot b/addons/hr_holidays/i18n/hr_holidays.pot index 889cd359751..750e38af69f 100644 --- a/addons/hr_holidays/i18n/hr_holidays.pot +++ b/addons/hr_holidays/i18n/hr_holidays.pot @@ -4072,6 +4072,12 @@ msgid "" "You must be either %s's manager or time off manager to approve this time off" msgstr "" +#. module: hr_holidays +#: code:addons/hr_holidays/models/hr_leave_allocation.py:0 +msgid "" +"You must either be a Time off Officer or Time off Manager to approve this leave" +"" + #. module: hr_holidays #: model:ir.model.constraint,message:hr_holidays.constraint_hr_leave_accrual_level_added_value_greater_than_zero msgid "You must give a rate greater than 0 in accrual plan levels." diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 94bae63a9f2..090fa09c897 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -1416,6 +1416,9 @@ class HolidaysRequest(models.Model): if not is_officer and self.env.user != holiday.employee_id.leave_manager_id: raise UserError(_('You must be either %s\'s manager or Time off Manager to approve this leave') % (holiday.employee_id.name)) + if not is_officer and (state == 'validate' and val_type == 'hr') and holiday.holiday_type == 'employee': + raise UserError(_('You must either be a Time off Officer or Time off Manager to approve this leave')) + # ------------------------------------------------------------ # Activity methods # ------------------------------------------------------------