[FIX]hr_employee_stats_sheet:convert public holidays in employee tz

This commit is contained in:
2025-11-05 11:41:08 +01:00
parent 20f04d710c
commit 54e3f32eda
2 changed files with 66 additions and 65 deletions

View File

@@ -1,9 +1,9 @@
import logging
import datetime
import pytz
from odoo import api, fields, models
from datetime import timedelta
from odoo.fields import Date
import pytz
from pytz import utc
_logger = logging.getLogger(__name__)
@@ -147,7 +147,7 @@ class HrEmployeeStats(models.Model):
total_leave_hours = leave_id.number_of_hours_display
elif leave_id.request_unit_half:
total_leave_hours = self._get_total_planned_hours() / 2
else:
else :
total_leave_hours = self._get_total_planned_hours()
return total_leave_hours
@@ -167,21 +167,21 @@ class HrEmployeeStats(models.Model):
stat.is_public_holiday = stat._is_public_holiday_accordig_to_employe_tz()
def _convert_to_employee_tz(self, date):
"""Convertit un datetime UTC en datetime dans le fuseau de l'employé."""
"""Convert a UTC datetime to the employee's timezone datetime."""
self.ensure_one()
if not date:
return None
employee_tz = pytz.timezone(self.sheet_id.employee_id.tz or "UTC")
employee_tz = pytz.timezone(self.employee_id.tz or "UTC")
if date.tzinfo is None:
dt = pytz.utc.localize(date)
return dt.astimezone(employee_tz) - timedelta(minutes=1)
return dt.astimezone(employee_tz)
def _is_public_holiday_accordig_to_employe_tz(self):
self.ensure_one()
if not self.date or not self.sheet_id or not self.sheet_id.employee_id:
if not self.date or not self.employee_id:
return False
#get public holidays for the employee
public_holidays = self.sheet_id.employee_id._get_public_holidays(
public_holidays = self.employee_id._get_public_holidays(
self.date, self.date
)
if not public_holidays:
@@ -198,13 +198,14 @@ class HrEmployeeStats(models.Model):
return True
else:
return False
def _get_gap_hours(
self, total_hours, total_recovery_hours, total_leave_hours, total_planned_hours
):
def _get_gap_hours(self, total_hours, total_recovery_hours, total_leave_hours, total_planned_hours):
self.ensure_one()
balance = (
total_hours + total_recovery_hours + total_leave_hours - total_planned_hours
total_hours
+ total_recovery_hours
+ total_leave_hours
- total_planned_hours
)
return balance