[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
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m29s
This commit is contained in:
@@ -2,4 +2,5 @@ from . import hr_employee_stats
|
||||
from . import hr_timesheet_sheet
|
||||
from . import res_config
|
||||
from . import res_company
|
||||
from . import hr_leave_allocation
|
||||
from . import hr_leave_allocation
|
||||
from . import hr_employee
|
||||
41
hr_employee_stats_sheet/models/hr_employee.py
Normal file
41
hr_employee_stats_sheet/models/hr_employee.py
Normal 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
|
||||
@@ -88,7 +88,7 @@ class HrEmployeeStats(models.Model):
|
||||
total_planned_hours = 0
|
||||
if self.employee_id and self.date and not self.is_public_holiday:
|
||||
dayofweek = int(self.date.strftime("%u")) - 1
|
||||
calendar_id = self.employee_id.resource_calendar_id
|
||||
calendar_id = self.employee_id._get_calendar_in_progress_during_a_time_period(self.date,self.date)
|
||||
week_number = self.date.isocalendar()[1] % 2
|
||||
if calendar_id.two_weeks_calendar:
|
||||
hours = calendar_id.attendance_ids.search(
|
||||
|
||||
@@ -100,42 +100,33 @@ class HrTimesheetSheet(models.Model):
|
||||
sheet.recovery_allocation_ids.write({"state": "refuse"})
|
||||
return res
|
||||
|
||||
def _get_contracts_in_progress_during_timesheet_sheet_time_period(self):
|
||||
"""
|
||||
get the contracts which was in progress during the timesheet sheet range time
|
||||
"""
|
||||
contracts = self.env["hr.contract"].search(
|
||||
[
|
||||
("employee_id", "=", self.employee_id.id),
|
||||
("state", "in", ("open", "close")),
|
||||
("date_start", "<=", self.date_end),
|
||||
"|",
|
||||
("date_end", "=", False), # pas de date de fin OU
|
||||
("date_end", ">=", self.date_start), # date de fin après le début
|
||||
],
|
||||
)
|
||||
return contracts
|
||||
# def _get_calendar_in_progress_during_timesheet_time_period(self):
|
||||
# """
|
||||
# get the ressource calendar which was used during the timesheet sheet time period
|
||||
# """
|
||||
# #find calendar(s) running over the duration of the timesheet
|
||||
# calendars = self.env["hr.employee.calendar"].search(
|
||||
# [
|
||||
# ("employee_id", "=", self.employee_id.id),
|
||||
|
||||
def _get_calendar_in_progress_during_timesheet_time_period(self):
|
||||
"""
|
||||
get the ressource calendar which was used during the timesheet sheet time period
|
||||
"""
|
||||
#checks if only one contract runs over the duration of the timesheet
|
||||
contracts = self._get_contracts_in_progress_during_timesheet_sheet_time_period()
|
||||
if len(contracts) > 1:
|
||||
# check if a new contract start during timesheet sheet time period. If yes, raise an error
|
||||
raise UserError(
|
||||
_("There is a contract starting during the timesheet sheet time period for the employee %s"
|
||||
"Please create a new timesheet sheet starting from the new contract start date")
|
||||
% self.employee_id.display_name
|
||||
)
|
||||
# get the ressource calendar id according to the work contract
|
||||
elif self.employee_id.resource_calendar_id:
|
||||
return self.employee_id.resource_calendar_id
|
||||
#get the ressource calendar linked to the employee
|
||||
elif self.env.company.resource_calendar_id:
|
||||
return self.env.company.resource_calendar_id
|
||||
return None
|
||||
# ("date_start", "<=", self.date_end),
|
||||
# "|",
|
||||
# ("date_end", "=", False), # pas de date de fin OU
|
||||
# ("date_end", ">=", self.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.employee_id.display_name
|
||||
# )
|
||||
# # get the ressource calendar id according to the work contract
|
||||
# elif calendars and calendars[0].calendar_id:
|
||||
# return calendars[0].calendar_id
|
||||
# #get the ressource calendar linked to the employee
|
||||
# elif self.env.company.resource_calendar_id:
|
||||
# return self.env.company.resource_calendar_id
|
||||
|
||||
def _get_working_hours_per_week(self):
|
||||
"""
|
||||
@@ -147,7 +138,7 @@ class HrTimesheetSheet(models.Model):
|
||||
:return: limit recovery hours
|
||||
"""
|
||||
# get ressource calendar id used during the timesheet sheet time period
|
||||
ressource_calendar_id = self._get_calendar_in_progress_during_timesheet_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:
|
||||
resource_calendar_attendance_ids = self.env[
|
||||
"resource.calendar.attendance"
|
||||
@@ -169,7 +160,7 @@ class HrTimesheetSheet(models.Model):
|
||||
:return: hours per day
|
||||
"""
|
||||
# get ressource calendar id used during the timesheet sheet time period
|
||||
ressource_calendar_id = self._get_calendar_in_progress_during_timesheet_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
|
||||
|
||||
Reference in New Issue
Block a user