[FIX]hr_employee_stats_sheet:use employee calendar hours per day to convert recovery hours into allocation days
Odoo displays allocation hours with the hours per day of the employee's resource calendar. Converting recovery hours with another calendar (planning calendar or company calendar) made the generated allocation display a wrong number of hours (e.g. 18.21h instead of 19h). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -102,18 +102,21 @@ class HrTimesheetSheet(models.Model):
|
||||
|
||||
def _get_working_hours_per_day(self):
|
||||
"""
|
||||
Get the hours per day for the employee according to:
|
||||
- the employee's work contract,
|
||||
- or their resource calendar,
|
||||
Get the hours per day used to convert recovery hours into allocation days.
|
||||
It must be the same ratio as the one used by Odoo to convert the allocation
|
||||
days back into hours (see hr.leave.allocation._compute_number_of_hours_display),
|
||||
otherwise the allocation won't display the recovery hours of the timesheet sheet:
|
||||
- the employee's resource calendar,
|
||||
- or the company's resource calendar,
|
||||
- or the default value of 8 hours per day.
|
||||
:return: hours per day
|
||||
"""
|
||||
# get ressource calendar id used during the timesheet sheet time period
|
||||
ressource_calendar_id = self.employee_id._get_calendar_in_progress_during_a_time_period(self.date_start,self.date_end)
|
||||
if ressource_calendar_id:
|
||||
return ressource_calendar_id.hours_per_day
|
||||
return HOURS_PER_DAY
|
||||
self.ensure_one()
|
||||
return (
|
||||
self.employee_id.sudo().resource_calendar_id.hours_per_day
|
||||
or self.company_id.resource_calendar_id.hours_per_day
|
||||
or HOURS_PER_DAY
|
||||
)
|
||||
|
||||
def action_generate_recovery_allocation(self):
|
||||
# check if the user has the right to review the timesheet sheet
|
||||
@@ -147,6 +150,9 @@ class HrTimesheetSheet(models.Model):
|
||||
# get recovery hours from total gap hours of the timesheet sheet
|
||||
recovery_hours = self._get_timesheet_sheet_recovery_hours()
|
||||
|
||||
# raise an error if the employee's calendar changes during the timesheet sheet time period
|
||||
employee_id._get_calendar_in_progress_during_a_time_period(self.date_start, self.date_end)
|
||||
|
||||
# convert recovery hours into days
|
||||
recovery_days = recovery_hours / self._get_working_hours_per_day()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user