diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 1c56af6cc52..96eb1a830a7 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -627,15 +627,16 @@ class HolidaysAllocation(models.Model): return True def action_confirm(self): - if self.filtered(lambda holiday: holiday.state != 'draft'): + if self.filtered(lambda holiday: holiday.state != 'draft' and holiday.validation_type != 'no'): raise UserError(_('Allocation request must be in Draft state ("To Submit") in order to confirm it.')) res = self.write({'state': 'confirm'}) self.activity_update() + self.filtered(lambda holiday: holiday.validation_type == 'no').action_validate() return res def action_validate(self): current_employee = self.env.user.employee_id - if any(holiday.state != 'confirm' for holiday in self): + if any(holiday.state != 'confirm' and holiday.validation_type != 'no' for holiday in self): raise UserError(_('Allocation request must be confirmed in order to approve it.')) self.write({ diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 23122351ec4..d4ee70386a4 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -81,7 +81,7 @@ class HolidaysType(models.Model): Not Allowed: User cannot request an allocation.""") allocation_validation_type = fields.Selection([ ('officer', 'Approved by Time Off Officer'), - ('no', 'No validation needed')], default='officer', string='Approval', + ('no', 'No validation needed')], default='no', string='Approval', compute='_compute_allocation_validation_type', store=True, readonly=False, help="""Select the level of approval needed in case of request by employee - No validation needed: The employee's request is automatically approved. diff --git a/addons/hr_holidays/security/hr_holidays_security.xml b/addons/hr_holidays/security/hr_holidays_security.xml index 637d5c29b10..f22cb8b72d1 100644 --- a/addons/hr_holidays/security/hr_holidays_security.xml +++ b/addons/hr_holidays/security/hr_holidays_security.xml @@ -166,9 +166,7 @@ ('holiday_status_id.employee_requests', '=', 'yes'), ('holiday_type', '=', 'employee'), '|', - '&', - ('employee_id.user_id', '=', user.id), - ('state', '!=', 'validate'), + ('employee_id.user_id', '=', user.id), '&', ('validation_type', '=', 'officer'), ('employee_id.leave_manager_id', '=', user.id), diff --git a/addons/hr_holidays/static/src/views/calendar/calendar_controller.js b/addons/hr_holidays/static/src/views/calendar/calendar_controller.js index 2c8505f1a85..a74f161b6d4 100644 --- a/addons/hr_holidays/static/src/views/calendar/calendar_controller.js +++ b/addons/hr_holidays/static/src/views/calendar/calendar_controller.js @@ -52,7 +52,6 @@ export class TimeOffCalendarController extends CalendarController { newAllocationRequest() { const context = { - 'default_state': 'confirm', 'form_view_ref': 'hr_holidays.hr_leave_allocation_view_form_dashboard', }; if (this.employeeId) { diff --git a/addons/hr_holidays/tests/test_accrual_allocations.py b/addons/hr_holidays/tests/test_accrual_allocations.py index 2e12ae2c1a1..232ec3cf1b8 100644 --- a/addons/hr_holidays/tests/test_accrual_allocations.py +++ b/addons/hr_holidays/tests/test_accrual_allocations.py @@ -18,6 +18,7 @@ class TestAccrualAllocations(TestHrHolidaysCommon): 'name': 'Paid Time Off', 'time_type': 'leave', 'requires_allocation': 'yes', + 'allocation_validation_type': 'officer', }) def setAllocationCreateDate(self, allocation_id, date): diff --git a/addons/hr_holidays_attendance/tests/test_holidays_overtime.py b/addons/hr_holidays_attendance/tests/test_holidays_overtime.py index bb4c75455de..4c3c255b0f9 100644 --- a/addons/hr_holidays_attendance/tests/test_holidays_overtime.py +++ b/addons/hr_holidays_attendance/tests/test_holidays_overtime.py @@ -45,6 +45,7 @@ class TestHolidaysOvertime(TransactionCase): 'company_id': cls.company.id, 'requires_allocation': 'yes', 'employee_requests': 'yes', + 'allocation_validation_type': 'officer', 'overtime_deductible': True, }) @@ -183,6 +184,7 @@ class TestHolidaysOvertime(TransactionCase): 'company_id': self.company.id, 'requires_allocation': 'yes', 'employee_requests': 'yes', + 'allocation_validation_type': 'officer', 'overtime_deductible': False, })