From 11a04b2bcada9e5073aaf2a2caf27f76ba73ee88 Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Wed, 8 Mar 2023 14:42:52 +0100
Subject: [PATCH] [fix] constraint only on timesheet analytic line
---
models/hr_timesheet.py | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py
index 8feb341..e2c50ae 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):
--
GitLab