diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index 4c9513c45809e963f1707f934cb26a18a1f8a2f9..131a7bd21caa58f55086f6ff5a1023a3d9b99973 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 # ------------------------------------------------------