Skip to content
Snippets Groups Projects
Commit 79136f97 authored by Benjamin - Le Filament's avatar Benjamin - Le Filament
Browse files

[cgscop #179] ajout contrainte sur imputations weekend et resource.calendar.leaves

parent 13d8b895
No related branches found
No related tags found
No related merge requests found
# © 2019 Le Filament (<http://www.le-filament.com>) # © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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 import models, fields, api
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
...@@ -108,6 +110,20 @@ class ScopHrTimesheet(models.Model): ...@@ -108,6 +110,20 @@ class ScopHrTimesheet(models.Model):
"Vous ne pourvez imputer plus de 8h sur la même journée.\n" "Vous ne pourvez imputer plus de 8h sur la même journée.\n"
"Journée du %s" % record.date.strftime("%d/%m/%Y")) "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 # Override ORM
# ------------------------------------------------------ # ------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment