forked from Yaltik/golem
[ADD]GOLEM Resource tests
[IMP]Resource validation to False, check dates
This commit is contained in:
parent
aeefceb970
commit
cb74acb4e6
@ -19,6 +19,7 @@
|
|||||||
""" GOLEM Resources management """
|
""" GOLEM Resources management """
|
||||||
|
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class GolemResource(models.Model):
|
class GolemResource(models.Model):
|
||||||
@ -30,7 +31,7 @@ class GolemResource(models.Model):
|
|||||||
|
|
||||||
name = fields.Char(required=True, index=True)
|
name = fields.Char(required=True, index=True)
|
||||||
active = fields.Boolean(default=True)
|
active = fields.Boolean(default=True)
|
||||||
validation_required = fields.Boolean(default=True,
|
validation_required = fields.Boolean(default=False,
|
||||||
string='Is validation required ?')
|
string='Is validation required ?')
|
||||||
type_id = fields.Many2one('golem.resource.type',
|
type_id = fields.Many2one('golem.resource.type',
|
||||||
index=True, string='Resource Type')
|
index=True, string='Resource Type')
|
||||||
@ -53,3 +54,11 @@ class GolemResource(models.Model):
|
|||||||
""" Toggles active boolean """
|
""" Toggles active boolean """
|
||||||
for resource in self:
|
for resource in self:
|
||||||
resource.active = not resource.active
|
resource.active = not resource.active
|
||||||
|
|
||||||
|
@api.constrains('avaibility_start', 'avaibility_stop')
|
||||||
|
def _check_date_consistency(self):
|
||||||
|
""" Checks date consistency """
|
||||||
|
for resource in self:
|
||||||
|
if resource.avaibility_stop <= resource.avaibility_start:
|
||||||
|
raise ValidationError(_('End availibility should be after than '
|
||||||
|
'start availibility'))
|
||||||
|
19
golem_resource/tests/__init__.py
Normal file
19
golem_resource/tests/__init__.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- 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/>.
|
||||||
|
|
||||||
|
from . import test_golem_resource, test_golem_resource_timetable
|
69
golem_resource/tests/test_golem_resource.py
Normal file
69
golem_resource/tests/test_golem_resource.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# -*- 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 testing """
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class TestGolemResource(TransactionCase):
|
||||||
|
""" GOLEM Resource testing """
|
||||||
|
|
||||||
|
def setUp(self, *args, **kwargs):
|
||||||
|
""" Bootstrap Resource """
|
||||||
|
super(TestGolemResource, self).setUp(*args, **kwargs)
|
||||||
|
self.data = {
|
||||||
|
'name': 'Resource',
|
||||||
|
'avaibility_start': '2018-01-01',
|
||||||
|
'avaibility_stop': '2020-01-01'
|
||||||
|
}
|
||||||
|
self.resource = self.env['golem.resource']
|
||||||
|
|
||||||
|
def test_resource_basic(self):
|
||||||
|
""" Test resource bases """
|
||||||
|
resource = self.resource.create(self.data)
|
||||||
|
self.assertTrue(resource.active)
|
||||||
|
self.assertFalse(resource.validation_required)
|
||||||
|
self.assertEqual(resource.avaibility_start, '2018-01-01')
|
||||||
|
self.assertEqual(resource.avaibility_stop, '2020-01-01')
|
||||||
|
self.assertFalse(resource.supervisor_id)
|
||||||
|
self.assertFalse(resource.product_tmpl_id)
|
||||||
|
self.assertFalse(resource.timetable_ids)
|
||||||
|
self.assertFalse(resource.reservation_ids)
|
||||||
|
|
||||||
|
def test_resource_active(self):
|
||||||
|
""" Test resource active """
|
||||||
|
resource = self.resource.create(self.data)
|
||||||
|
self.assertTrue(resource.active)
|
||||||
|
resource.active_toggle()
|
||||||
|
self.assertFalse(resource.active)
|
||||||
|
resource.active_toggle()
|
||||||
|
self.assertTrue(resource.active)
|
||||||
|
|
||||||
|
def test_resource_dates(self):
|
||||||
|
""" Test resource dates : stop can not be after start """
|
||||||
|
self.data.update({'avaibility_stop': '2017-01-01'})
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
self.resource.create(self.data)
|
||||||
|
|
||||||
|
def test_resource_dates_equal(self):
|
||||||
|
""" Test resource dates : stop can not be equal to start """
|
||||||
|
self.data.update({'avaibility_stop': self.data['avaibility_start']})
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
self.resource.create(self.data)
|
Loading…
Reference in New Issue
Block a user