2018-02-18 14:10:30 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
|
|
|
# Copyright 2018 Fabien Bourgeois <fabien@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 Resource Timetable """
|
|
|
|
|
|
|
|
from odoo import models, fields, api, _
|
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
|
|
class GolemTimetable(models.Model):
|
|
|
|
""" Golem Timetable """
|
|
|
|
_name = "golem.resource.timetable"
|
|
|
|
_description = "Golem Timetable"
|
|
|
|
_rec_name = 'weekday'
|
2018-02-18 17:36:01 +01:00
|
|
|
_order = 'weekday asc,time_start asc'
|
2018-02-18 14:10:30 +01:00
|
|
|
|
|
|
|
resource_id = fields.Many2one('golem.resource', required=True,
|
|
|
|
string='Linked resource')
|
|
|
|
weekday = fields.Selection([('0', _('Monday')),
|
|
|
|
('1', _('Tuesday')),
|
|
|
|
('2', _('Wednesday')),
|
|
|
|
('3', _('Thursday')),
|
|
|
|
('4', _('Friday')),
|
|
|
|
('5', _('Saturday')),
|
2018-02-18 14:53:53 +01:00
|
|
|
('6', _('Sunday'))], required=True)
|
2018-02-18 14:10:30 +01:00
|
|
|
time_start = fields.Float(required=True, string='Start')
|
|
|
|
time_stop = fields.Float(required=True, string='Stop')
|
|
|
|
|
2018-02-18 14:53:53 +01:00
|
|
|
@api.onchange('time_start')
|
|
|
|
def onchange_time_start(self):
|
|
|
|
""" Propose automatically stop hour after start hour had been filled """
|
|
|
|
for line in self:
|
|
|
|
if line.time_start and not line.time_stop:
|
|
|
|
line.time_stop = line.time_start + 1
|
|
|
|
|
2018-02-18 14:10:30 +01:00
|
|
|
@api.constrains('time_start', 'time_stop')
|
|
|
|
def _check_time_consistency(self):
|
2018-02-18 14:53:53 +01:00
|
|
|
""" Checks time consistency """
|
2018-02-18 14:10:30 +01:00
|
|
|
for timetable in self:
|
2018-02-19 06:50:04 +01:00
|
|
|
if timetable.time_stop <= timetable.time_start:
|
2018-02-18 14:10:30 +01:00
|
|
|
raise ValidationError(_('End time should be after than start time'))
|