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-03-11 21:50:18 +01:00
|
|
|
availibility_24 = fields.Boolean(string="All day")
|
2018-03-12 12:48:09 +01:00
|
|
|
#@api.onchange('availibility_24')
|
|
|
|
#def _set_time_start_stop(self):
|
|
|
|
# """ set start and stop time """
|
|
|
|
# self.ensure_one()
|
|
|
|
# if self.availibility_24:
|
|
|
|
# self.time_start = 0.0
|
|
|
|
# self.time_stop = 23.99
|
|
|
|
|
2018-03-11 21:50:18 +01:00
|
|
|
|
2018-03-12 12:48:09 +01:00
|
|
|
@api.onchange('availibility_24')
|
|
|
|
def onchange_availibility_24(self):
|
|
|
|
""" Propose automatically stop hour after start hour had been filled """
|
|
|
|
for line in self:
|
|
|
|
if line.availibility_24:
|
|
|
|
line.time_start = 0.0
|
|
|
|
line.time_stop = 23.98
|
2018-02-18 14:10:30 +01:00
|
|
|
|
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'))
|
2018-03-11 21:50:18 +01:00
|
|
|
|
|
|
|
@api.constrains('time_start', 'time_stop')
|
|
|
|
def _check_time_all_day(self):
|
|
|
|
""" Checks time all day availibility """
|
|
|
|
for timetable in self:
|
|
|
|
if timetable.time_stop > 23.98 and timetable.time_start == 0:
|
|
|
|
timetable.write({'availibility_24': True})
|