forked from Yaltik/golem
[ADD]GOLEM Resource Timetable tests
[IMP]Do not allow equal times between start and stop
This commit is contained in:
parent
cb74acb4e6
commit
94f905b90e
@ -51,5 +51,5 @@ class GolemTimetable(models.Model):
|
||||
def _check_time_consistency(self):
|
||||
""" Checks time consistency """
|
||||
for timetable in self:
|
||||
if timetable.time_stop < timetable.time_start:
|
||||
if timetable.time_stop <= timetable.time_start:
|
||||
raise ValidationError(_('End time should be after than start time'))
|
||||
|
58
golem_resource/tests/test_golem_resource_timetable.py
Normal file
58
golem_resource/tests/test_golem_resource_timetable.py
Normal file
@ -0,0 +1,58 @@
|
||||
# -*- 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 testing """
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class TestGolemResourceTimetable(TransactionCase):
|
||||
""" GOLEM Resource Timetable testing """
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
""" Bootstrap timetable """
|
||||
super(TestGolemResourceTimetable, self).setUp(*args, **kwargs)
|
||||
self.resource = self.env['golem.resource'].create({
|
||||
'name': 'Resource',
|
||||
'validation_required': False,
|
||||
'avaibility_start': '2018-01-01',
|
||||
'avaibility_stop': '2020-01-01'
|
||||
})
|
||||
self.timetable = self.env['golem.resource.timetable']
|
||||
self.data = {'resource_id': self.resource.id,
|
||||
'weekday': '0',
|
||||
'time_start': 8.0,
|
||||
'time_stop': 10.0}
|
||||
|
||||
def test_timetable_basic(self):
|
||||
""" Test Timetable bases """
|
||||
timetable = self.timetable.create(self.data)
|
||||
self.assertEqual(timetable.resource_id, self.resource)
|
||||
self.assertEqual(timetable.time_start, 8.0)
|
||||
self.assertEqual(timetable.time_stop, 10.0)
|
||||
self.assertEqual(timetable, self.resource.timetable_ids[0])
|
||||
|
||||
def test_timetable_times(self):
|
||||
""" Test timetable times : stop can not be equal or after start """
|
||||
self.data.update({'time_stop': 7.0})
|
||||
with self.assertRaises(ValidationError):
|
||||
self.timetable.create(self.data)
|
||||
self.data.update({'time_stop': self.data['time_start']})
|
||||
with self.assertRaises(ValidationError):
|
||||
self.timetable.create(self.data)
|
Loading…
Reference in New Issue
Block a user