GOLEM/golem_resource_holiday/models/golem_resource_reservation.py

42 lines
2.1 KiB
Python
Raw Normal View History

2020-05-22 21:53:24 +02:00
# -*- coding: utf-8 -*-
# Copyright 2020 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2020 Youssef El Ouahby <youssef@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
""" GOLEM Resources Reservation Adaptations """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemResourceReservation(models.Model):
""" GOLEM Resource Reservation Model """
_inherit = 'golem.resource.reservation'
@api.constrains('resource_id', 'date_start', 'date_stop')
def check_resource_holiday_date(self):
for reservation in self:
resource_holiday = reservation.resource_id.holiday_selection_ids.filtered(lambda s: not s.is_reservation_possible)
if resource_holiday:
for holiday in resource_holiday:
if (holiday.holiday_id.date_start < reservation.date_start < holiday.holiday_id.date_end) or \
(holiday.holiday_id.date_start < reservation.date_stop < holiday.holiday_id.date_end):
raise ValidationError(_('This resource cannot be reserved during the'
' period between {} and {}, as there is a holiday, please choose '
'another date').format(holiday.holiday_id.date_start,
holiday.holiday_id.date_end
))