From 8fdb247d7cfcfe89bab826c164c8d993bc6b789e Mon Sep 17 00:00:00 2001 From: Vishnu Thuletiya Date: Tue, 17 Mar 2020 04:38:35 +0000 Subject: [PATCH] [FIX] hr_holidays: Fix the wrong behavior of no-validation leave type Currently when you create time off type with no validation and then create new time off request, save and status is approved. However, if you refuse the time off and reset to Draft and confirm it then status will be 'To approve' when it should be 'Approved'. So after this commit, on confirm of refused time off with validation type 'no validation' automatically move to the 'Approved' instead of 'To Approve'. closes odoo/odoo#48087 Taskid: 2206222 Closes: #47738 X-original-commit: 3d2391d350ea7ed572cf6818ab3f607c99fe0bf5 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_holidays/models/hr_leave.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 25bf85e595d..0ad2618177b 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -891,6 +891,10 @@ class HolidaysRequest(models.Model): if self.filtered(lambda holiday: holiday.state != 'draft'): raise UserError(_('Time off request must be in Draft state ("To Submit") in order to confirm it.')) self.write({'state': 'confirm'}) + holidays = self.filtered(lambda leave: leave.validation_type == 'no_validation') + if holidays: + # Automatic validation should be done in sudo, because user might not have the rights to do it by himself + holidays.sudo().action_validate() self.activity_update() return True