[IMP]hr_employee_stats_sheet:add dependecie to hr_employee_calendar_planning and identifies the planning using by a employee during a time period
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m29s

This commit is contained in:
2025-12-10 14:49:53 +01:00
parent 5b103056d6
commit dfd5f26e95
6 changed files with 145 additions and 100 deletions

View File

@@ -0,0 +1,41 @@
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
],
)
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 no hr_employee_calendar found, use employee resource_calendar_id
elif self.resource_calendar_id:
return self.resource_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