The planned hours of each day searched the employee calendar history, then the calendar attendances, day by day. The days computed together now share one search of the calendar histories and one of the attendances. The calendar of a day is chosen by the same rule as before, now in ``_select_stats_calendar`` and shared with ``_get_calendar_in_progress_during_a_time_period``: the history line covering the day, else the company calendar, and an error when two lines cover it. Assisted-by: Claude:claude-opus-5-5 Assisted-by: GPT:gpt-6.1-sol Assisted-by: GPT:gpt-6.2-astra-ultrafast
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
import pytz
|
|
from odoo import models, _
|
|
from datetime import timedelta
|
|
from pytz import utc
|
|
from odoo.exceptions import UserError
|
|
|
|
class HrEmployee(models.Model):
|
|
_inherit = "hr.employee"
|
|
|
|
def _get_calendar_in_progress_during_a_time_period(self, date_start, date_end):
|
|
"""
|
|
get the ressource calendar which was used during the timesheet sheet time period
|
|
"""
|
|
self.ensure_one()
|
|
# find calendar(s) running over the duration of the timesheet
|
|
calendars = self.env["hr.employee.calendar"].search(
|
|
[
|
|
("employee_id", "=", self.id),
|
|
|
|
("date_start", "<=", date_end),
|
|
"|",
|
|
("date_end", "=", False), # pas de date de fin OU
|
|
("date_end", ">=", date_start), # date de fin après le début
|
|
],
|
|
)
|
|
return self._select_stats_calendar(calendars)
|
|
|
|
def _select_stats_calendar(self, calendars):
|
|
"""
|
|
get the ressource calendar to use, given the hr_employee_calendar
|
|
lines running over the period
|
|
"""
|
|
self.ensure_one()
|
|
if len(calendars) > 1:
|
|
raise UserError(
|
|
_("There is a calendar starting during the timesheet sheet time period for the employee %s "
|
|
"Please create a new timesheet sheet starting from the new calendar start date")
|
|
% self.display_name
|
|
)
|
|
# if hr_employee_calendar found, use its calendar_id
|
|
elif calendars and calendars[0].calendar_id:
|
|
return calendars[0].calendar_id
|
|
# if resource calendar not found, use the ressource calendar of the company linked to the employee
|
|
elif self.company_id.resource_calendar_id:
|
|
return self.company_id.resource_calendar_id
|
|
return None |