From 25cd4c61f4d733acb00d4af8ae98f89651f3abeb Mon Sep 17 00:00:00 2001 From: Kevin Baptiste <kba@odoo.com> Date: Tue, 22 Nov 2022 15:30:04 +0000 Subject: [PATCH] [FIX] hr_(holidays_)attendance: recompute overtime on leaves > 1 day 1/ When approving / refusing a leave spanning multiple days, the overtimes were only recomputed for the starting date and not the whole period. 2/ Overtimes should be computed whatever the kind of time off that's been taken (Absence or Other). task-3073155 closes odoo/odoo#106736 X-original-commit: 116d7cb46132404354e00e67a2364b8239fcdce5 Signed-off-by: Kevin Baptiste <kba@odoo.com> --- addons/hr_attendance/models/hr_attendance.py | 2 +- addons/hr_holidays_attendance/models/hr_leave.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/hr_attendance/models/hr_attendance.py b/addons/hr_attendance/models/hr_attendance.py index eb46b60e5304..08d6c714d17f 100644 --- a/addons/hr_attendance/models/hr_attendance.py +++ b/addons/hr_attendance/models/hr_attendance.py @@ -163,7 +163,7 @@ class HrAttendance(models.Model): start, stop, emp.resource_id )[emp.resource_id.id] # Substract Global Leaves and Employee's Leaves - leave_intervals = emp.resource_calendar_id._leave_intervals_batch(start, stop, emp.resource_id) + leave_intervals = emp.resource_calendar_id._leave_intervals_batch(start, stop, emp.resource_id, domain=[]) expected_attendances -= leave_intervals[False] | leave_intervals[emp.resource_id.id] # working_times = {date: [(start, stop)]} diff --git a/addons/hr_holidays_attendance/models/hr_leave.py b/addons/hr_holidays_attendance/models/hr_leave.py index ec5fe57fe02b..c10df0f61493 100644 --- a/addons/hr_holidays_attendance/models/hr_leave.py +++ b/addons/hr_holidays_attendance/models/hr_leave.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from collections import defaultdict +from datetime import timedelta from odoo import api, fields, models, _ from odoo.exceptions import ValidationError @@ -95,6 +96,7 @@ class HRLeave(models.Model): employee_dates = defaultdict(set) for leave in self: if leave.employee_id and leave.employee_company_id.hr_attendance_overtime: - employee_dates[leave.employee_id].add(self.env['hr.attendance']._get_day_start_and_day(leave.employee_id, leave.date_from)) + for d in range((leave.date_to - leave.date_from).days + 1): + employee_dates[leave.employee_id].add(self.env['hr.attendance']._get_day_start_and_day(leave.employee_id, leave.date_from + timedelta(days=d))) if employee_dates: self.env['hr.attendance']._update_overtime(employee_dates) -- GitLab