From 79136f978d561fc0e48ef930f5f4ada784d395f9 Mon Sep 17 00:00:00 2001 From: Benjamin <benjamin@le-filament.com> Date: Wed, 25 Mar 2020 16:21:27 +0100 Subject: [PATCH] [cgscop #179] ajout contrainte sur imputations weekend et resource.calendar.leaves --- models/hr_timesheet.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index 4c9513c..131a7bd 100644 --- a/models/hr_timesheet.py +++ b/models/hr_timesheet.py @@ -1,6 +1,8 @@ # © 2019 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from datetime import datetime, time + from odoo import models, fields, api from odoo.exceptions import UserError, ValidationError @@ -108,6 +110,20 @@ class ScopHrTimesheet(models.Model): "Vous ne pourvez imputer plus de 8h sur la même journée.\n" "Journée du %s" % record.date.strftime("%d/%m/%Y")) + @api.constrains('date') + def _check_weekday(self): + for line in self: + dt = datetime.combine(line.date, time(12, 00)) + holiday = self.env['resource.calendar.leaves'].search([ + ('company_id', '=', self.env.user.company_id.id), + ('date_from', '<=', dt), + ('date_to', '>=', dt), + ]) + if line.date.weekday() in (5, 6) or holiday: + raise ValidationError( + "Vous ne pourvez imputer du temps sur un weekend " + "ou un jour férié.") + # ------------------------------------------------------ # Override ORM # ------------------------------------------------------ -- GitLab