From bf0ff1350ab7a71bcfd4bc7e1e9c377885060e06 Mon Sep 17 00:00:00 2001 From: Stephane Mangin Date: Tue, 16 Jan 2024 15:08:42 +0100 Subject: [PATCH] [FIX] hr_attendance_report_theoretical_time: invalid recomputation of leaves using the wizard --- .../wizards/recompute_theoretical_attendance.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hr_attendance_report_theoretical_time/wizards/recompute_theoretical_attendance.py b/hr_attendance_report_theoretical_time/wizards/recompute_theoretical_attendance.py index 56e888f9..3a0cd97f 100644 --- a/hr_attendance_report_theoretical_time/wizards/recompute_theoretical_attendance.py +++ b/hr_attendance_report_theoretical_time/wizards/recompute_theoretical_attendance.py @@ -22,6 +22,20 @@ class RecomputeTheoreticalAttendance(models.TransientModel): def action_recompute(self): self.ensure_one() + # First we need to manage leaves (as they are linked to the calendar + # and need to be removed and added back to be correctly processed) + leave_model = self.env["hr.leave"] + leaves = leave_model.search([ + ("employee_id", "in", self.employee_ids.ids), + # Here we need to include leaves even partially contained in + # the date range. Otherwise leaves won't be retrieved. + ("date_from", ">=", self.date_from), + ("date_from", "<=", self.date_to), + ]) + leaves._remove_resource_leave() + leaves._create_resource_leave() + leaves._check_theoretical_hours() + # Then we can process remaining attendances attendances = self.env["hr.attendance"].search( [ ("employee_id", "in", self.employee_ids.ids),