Hi Ricardo, I have created an automated action that checks timesheet registration based on the start and end date of the task. I think you could change part of the code. Our problem is that our consutlants shouldn't be able to write time for dates outside the start:end date of a taks. Even when e.g. the project manager hasn't put the task in a folded stage.
- The timesheet_datetime_start is set to the start of the day (00:00:00) of the timesheet entry's date.
- The timesheet_datetime_end is set to the end of the day (23:59:59) of the timesheet entry's date.
- These datetime objects are then used for comparison with the task's planned start and end dates.
Here's the code:
task = record.task_id
timesheet_date = record.date # or 'date_time', depending on your setup
if task and task.planned_date_begin and task.planned_date_end:
# Convert timesheet_date to datetime for comparison
timesheet_datetime_start = datetime.datetime(timesheet_date.year, timesheet_date.month, timesheet_date.day)
timesheet_datetime_end = datetime.datetime(timesheet_date.year, timesheet_date.month, timesheet_date.day, 23, 59, 59)
if not (task.planned_date_begin <= timesheet_datetime_start <= task.planned_date_end or
task.planned_date_begin <= timesheet_datetime_end <= task.planned_date_end):
raise UserError("You cannot log time outside the task's scheduled dates.")
Hi Ricardo Gross,
You can add logic in create method of timesheet.