1 Commits

2 changed files with 11 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "hr_employee_stats_sheet", "name": "hr_employee_stats_sheet",
"version": "16.0.2.0.0", "version": "16.0.3.0.0",
"description": "Add global sheet for employee stats", "description": "Add global sheet for employee stats",
"summary": "Add global sheet for employee stats", "summary": "Add global sheet for employee stats",
"author": "Nicolas JEUDY", "author": "Nicolas JEUDY",
@@ -15,6 +15,7 @@
"hr_timesheet", "hr_timesheet",
"hr_timesheet_sheet", "hr_timesheet_sheet",
"resource", "resource",
"hr_employee_calendar_planning",
], ],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",

View File

@@ -100,38 +100,29 @@ class HrTimesheetSheet(models.Model):
sheet.recovery_allocation_ids.write({"state": "refuse"}) sheet.recovery_allocation_ids.write({"state": "refuse"})
return res return res
def _get_contracts_in_progress_during_timesheet_sheet_time_period(self): def _get_calendar_in_progress_during_timesheet_time_period(self):
""" """
get the contracts which was in progress during the timesheet sheet range time get the ressource calendar which was used during the timesheet sheet time period
""" """
contracts = self.env["hr.contract"].search( #find calendar(s) running over the duration of the timesheet
calendars = self.env["hr.employee.calendar"].search(
[ [
("employee_id", "=", self.employee_id.id), ("employee_id", "=", self.employee_id.id),
("state", "in", ("open", "close")),
("date_start", "<=", self.date_end), ("date_start", "<=", self.date_end),
"|", "|",
("date_end", "=", False), # pas de date de fin OU ("date_end", "=", False), # pas de date de fin OU
("date_end", ">=", self.date_start), # date de fin après le début ("date_end", ">=", self.date_start), # date de fin après le début
], ],
) )
return contracts if len(calendars) > 1:
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( raise UserError(
_("There is a contract starting during the timesheet sheet time period for the employee %s" _("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 contract start date") "Please create a new timesheet sheet starting from the new calendar start date")
% self.employee_id.display_name % self.employee_id.display_name
) )
# get the ressource calendar id according to the work contract # get the ressource calendar id according to the work contract
elif self.employee_id.resource_calendar_id: elif calendars and calendars[0].calendar_id:
return self.employee_id.resource_calendar_id return calendars[0].calendar_id
#get the ressource calendar linked to the employee #get the ressource calendar linked to the employee
elif self.env.company.resource_calendar_id: elif self.env.company.resource_calendar_id:
return self.env.company.resource_calendar_id return self.env.company.resource_calendar_id