diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index 8feb341e11cd6818b5c0f50fcf00f675461c78a7..e2c50ae1660e29d6146e9f72ea809c7e5f078936 100644 --- a/models/hr_timesheet.py +++ b/models/hr_timesheet.py @@ -157,27 +157,28 @@ class ScopHrTimesheet(models.Model): @api.constrains("unit_amount", "date") def _check_hours(self): for record in self: - lines = self.search( - [ - ("date", "=", record.date), - ("employee_id", "=", record.employee_id.id), - ] - ) - total = sum(lines.mapped("unit_amount")) - if ( - not self.env.company.day_working - and total > self.env.company.day_duration - ): - raise ValidationError( - _( - "Vous ne pouvez imputer plus de %sh sur la même journée.\n" - "Journée du %s" - ) - % ( - self.env.company.day_duration, - record.date.strftime("%d/%m/%Y"), - ) + if record.project_id: + lines = self.search( + [ + ("date", "=", record.date), + ("employee_id", "=", record.employee_id.id), + ] ) + total = sum(lines.mapped("unit_amount")) + if ( + not self.env.company.day_working + and total > self.env.company.day_duration + ): + raise ValidationError( + _( + "Vous ne pouvez imputer plus de %sh sur la même journée.\n" + "Journée du %s" + ) + % ( + self.env.company.day_duration, + record.date.strftime("%d/%m/%Y"), + ) + ) @api.constrains("date") def _check_weekday(self):