Skip to Content
Menu
This question has been flagged
2 Replies
1533 Views

"Timesheet validation rules define whether data entered in a timesheet is valid. If, based on a validation rule, data is found to be invalid, a warning or error will occur. Depending on the workflow conditions, the system may prevent users from submitting a timesheet if it contains errors or warnings." 

Is this available in Odoo17 

If I enter some time entries, which is higher or lesser than the required amount. Will the Odoo be able to show up a warning or error message.

Can anyone put forward a helping hand.

Avatar
Discard
Best Answer

Without development, in Odoo 17, you can do this with an automation rule:

turn on developer mode (go to settings, scroll down, click developer mode)

add a new automation rule (just type automation rule in the main menu to find this)

Say, your new automation rule has id = 999

as model, type account.analytic.line to get the analytic line which is used for timesheet entries.

as trigger, use "Save"

as "apply on" Domain, set  "Timesheet Line is set" and amount > 10 which will result in this domain:
[("is_timesheet", "=", True),("unit_amount", ">", 10)]

then add the python code: 

raise UserError("Time spent is higher than the maximum 10 hours")

Hope that helps!


Avatar
Discard

What if the validation must be "reported time must be less than project available time"?

@Eduardo Godyla

you could use a python code like this on the automation rule:

for rec in records
# Check if the entry is related to a task
if rec.task_id:
# Get the related task
task = rec.task_id

# Calculate the total time already logged on the task
total_logged_hours = sum(task.timesheet_ids.mapped('unit_amount'))

# Check if total logged hours exceed planned hours
if task.planned_hours and total_logged_hours > task.planned_hours:
raise ValidationError(_(
"The total logged time on task '%s' exceeds its planned hours. "
"Planned: %.2f, Current: %.2f (including your entry of %.2f)."
) % (task.name, task.planned_hours, total_logged_hours, rec.unit_amount))

Best Answer

Hello Cruz,


I hope you are doing well.


In this implementation, we use Odoo's context to temporarily bypass constraints during specific operations, such as record deletion in a one2many field. By adding a custom context key (skip_constraints=True), we control when constraints and field recomputations are applied, avoiding errors caused by intermediate states during a write() operation. This ensures that constraints are only enforced once all operations are complete and the data is consistent, preventing premature constraint checks that could otherwise lead to issues.


I hope this helps!


Thanks & Regards,

Avatar
Discard