[FIX]hr_employee_stats_sheet:fix calculation of planned recovery when recovery takes several days

This commit is contained in:
2025-12-08 16:15:05 +01:00
parent 726e34febc
commit c16fccfa6e
2 changed files with 14 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "hr_employee_stats_sheet",
"version": "16.0.2.1.0",
"version": "16.0.2.1.1",
"description": "Add global sheet for employee stats",
"summary": "Add global sheet for employee stats",
"author": "Nicolas JEUDY",

View File

@@ -113,17 +113,23 @@ class HrEmployeeStats(models.Model):
recovery = self.env["hr.leave"]
total_recovery_hours = 0
if self.date and self.employee_id and self._get_holiday_status_id():
recovery_ids = recovery.search(
recovery_id = recovery.search(
[
("employee_id", "=", self.employee_id.id),
("holiday_status_id", "=", self._get_holiday_status_id()),
("request_date_from", "<=", self.date),
("request_date_to", ">=", self.date),
]
)
total_recovery_hours = sum(
recovery_ids.mapped("number_of_hours_display")
],
limit=1
)
if recovery_id:
if recovery_id.request_unit_hours:
recovery_hours = recovery_id.number_of_hours_display
total_recovery_hours = min(recovery_hours,self._get_total_planned_hours())
elif recovery_id.request_unit_half:
total_recovery_hours = self._get_total_planned_hours() / 2
else :
total_recovery_hours = self._get_total_planned_hours()
return total_recovery_hours
def _get_total_leave_hours(self):
@@ -142,7 +148,8 @@ class HrEmployeeStats(models.Model):
)
if leave_id:
if leave_id.request_unit_hours:
total_leave_hours = leave_id.number_of_hours_display
leave_hours = leave_id.number_of_hours_display
total_leave_hours = min(leave_hours,self._get_total_planned_hours())
elif leave_id.request_unit_half:
total_leave_hours = self._get_total_planned_hours() / 2
else :