Browse Source

[PATCH] [ADD] date_range: multicompany tests

pull/1430/head
mreficent 6 years ago
committed by Laurent Mignon (ACSONE)
parent
commit
27ad43f9ff
  1. 63
      date_range/tests/test_date_range.py
  2. 44
      date_range/tests/test_date_range_generator.py
  3. 31
      date_range/tests/test_date_range_type.py

63
date_range/tests/test_date_range.py

@ -10,45 +10,55 @@ class DateRangeTest(TransactionCase):
def setUp(self): def setUp(self):
super(DateRangeTest, self).setUp() super(DateRangeTest, self).setUp()
self.date_range = self.env['date.range']
self.type = self.env['date.range.type'].create( self.type = self.env['date.range.type'].create(
{'name': 'Fiscal year', {'name': 'Fiscal year',
'company_id': False, 'company_id': False,
'allow_overlap': False}) 'allow_overlap': False})
self.company = self.env['res.company'].create({
'name': 'Test company',
})
self.company_2 = self.env['res.company'].create({
'name': 'Test company 2',
'parent_id': self.company.id,
})
self.typeB = self.env['date.range.type'].create(
{'name': 'Fiscal year B',
'company_id': self.company.id,
'allow_overlap': False})
def test_default_company(self): def test_default_company(self):
date_range = self.env['date.range']
dt = date_range.create({
dr = self.date_range.create({
'name': 'FS2016', 'name': 'FS2016',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2016-12-31', 'date_end': '2016-12-31',
'type_id': self.type.id, 'type_id': self.type.id,
}) })
self.assertTrue(dt.company_id)
self.assertTrue(dr.company_id)
# you can specify company_id to False # you can specify company_id to False
dt = date_range.create({
dr = self.date_range.create({
'name': 'FS2016_NO_COMPANY', 'name': 'FS2016_NO_COMPANY',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2016-12-31', 'date_end': '2016-12-31',
'type_id': self.type.id, 'type_id': self.type.id,
'company_id': False 'company_id': False
}) })
self.assertFalse(dt.company_id)
self.assertFalse(dr.company_id)
def test_empty_company(self): def test_empty_company(self):
date_range = self.env['date.range']
dt = date_range.create({
dr = self.date_range.create({
'name': 'FS2016', 'name': 'FS2016',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2016-12-31', 'date_end': '2016-12-31',
'type_id': self.type.id, 'type_id': self.type.id,
'company_id': None, 'company_id': None,
}) })
self.assertEqual(dt.name, 'FS2016')
self.assertEqual(dr.name, 'FS2016')
def test_invalid(self): def test_invalid(self):
date_range = self.env['date.range']
with self.assertRaises(ValidationError) as cm: with self.assertRaises(ValidationError) as cm:
date_range.create({
self.date_range.create({
'name': 'FS2016', 'name': 'FS2016',
'date_end': '2015-01-01', 'date_end': '2015-01-01',
'date_start': '2016-12-31', 'date_start': '2016-12-31',
@ -59,15 +69,14 @@ class DateRangeTest(TransactionCase):
'FS2016 is not a valid range (2016-12-31 > 2015-01-01)') 'FS2016 is not a valid range (2016-12-31 > 2015-01-01)')
def test_overlap(self): def test_overlap(self):
date_range = self.env['date.range']
date_range.create({
self.date_range.create({
'name': 'FS2015', 'name': 'FS2015',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2015-12-31', 'date_end': '2015-12-31',
'type_id': self.type.id, 'type_id': self.type.id,
}) })
with self.assertRaises(ValidationError) as cm, self.env.cr.savepoint(): with self.assertRaises(ValidationError) as cm, self.env.cr.savepoint():
date_range.create({
self.date_range.create({
'name': 'FS2016', 'name': 'FS2016',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2016-12-31', 'date_end': '2016-12-31',
@ -76,7 +85,7 @@ class DateRangeTest(TransactionCase):
self.assertEqual(cm.exception.name, 'FS2016 overlaps FS2015') self.assertEqual(cm.exception.name, 'FS2016 overlaps FS2015')
# check it's possible to overlap if it's allowed by the date range type # check it's possible to overlap if it's allowed by the date range type
self.type.allow_overlap = True self.type.allow_overlap = True
dr = date_range.create({
dr = self.date_range.create({
'name': 'FS2016', 'name': 'FS2016',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2016-12-31', 'date_end': '2016-12-31',
@ -85,8 +94,7 @@ class DateRangeTest(TransactionCase):
self.assertEquals(dr.name, 'FS2016') self.assertEquals(dr.name, 'FS2016')
def test_domain(self): def test_domain(self):
date_range = self.env['date.range']
dr = date_range.create({
dr = self.date_range.create({
'name': 'FS2015', 'name': 'FS2015',
'date_start': '2015-01-01', 'date_start': '2015-01-01',
'date_end': '2015-12-31', 'date_end': '2015-12-31',
@ -98,3 +106,26 @@ class DateRangeTest(TransactionCase):
domain, domain,
[('my_field', '>=', '2015-01-01'), [('my_field', '>=', '2015-01-01'),
('my_field', '<=', '2015-12-31')]) ('my_field', '<=', '2015-12-31')])
def test_date_range_multicompany_1(self):
dr = self.date_range.new({
'name': 'FS2016',
'date_start': '2015-01-01',
'date_end': '2016-12-31',
'type_id': self.typeB.id,
'company_id': self.company.id,
})
dr._cache.update(dr._convert_to_cache(
{'company_id': self.company_2.id}, update=True))
dr._onchange_company_id()
self.assertFalse(dr.type_id)
def test_date_range_multicompany_2(self):
with self.assertRaises(ValidationError):
self.date_range.create({
'name': 'FS2016',
'date_start': '2015-01-01',
'date_end': '2016-12-31',
'type_id': self.typeB.id,
'company_id': self.company_2.id,
})

44
date_range/tests/test_date_range_generator.py

@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)nses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)nses/agpl).
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
from dateutil.rrule import MONTHLY from dateutil.rrule import MONTHLY
@ -10,14 +11,26 @@ class DateRangeGeneratorTest(TransactionCase):
def setUp(self): def setUp(self):
super(DateRangeGeneratorTest, self).setUp() super(DateRangeGeneratorTest, self).setUp()
self.generator = self.env['date.range.generator']
self.type = self.env['date.range.type'].create( self.type = self.env['date.range.type'].create(
{'name': 'Fiscal year', {'name': 'Fiscal year',
'company_id': False, 'company_id': False,
'allow_overlap': False}) 'allow_overlap': False})
self.company = self.env['res.company'].create({
'name': 'Test company',
})
self.company_2 = self.env['res.company'].create({
'name': 'Test company 2',
'parent_id': self.company.id,
})
self.typeB = self.env['date.range.type'].create(
{'name': 'Fiscal year B',
'company_id': self.company.id,
'allow_overlap': False})
def test_generate(self): def test_generate(self):
generator = self.env['date.range.generator']
generator = generator.create({
generator = self.generator.create({
'date_start': '1943-01-01', 'date_start': '1943-01-01',
'name_prefix': '1943-', 'name_prefix': '1943-',
'type_id': self.type.id, 'type_id': self.type.id,
@ -32,3 +45,30 @@ class DateRangeGeneratorTest(TransactionCase):
self.assertEqual(range4.date_start, '1943-10-01') self.assertEqual(range4.date_start, '1943-10-01')
self.assertEqual(range4.date_end, '1943-12-31') self.assertEqual(range4.date_end, '1943-12-31')
self.assertEqual(range4.type_id, self.type) self.assertEqual(range4.type_id, self.type)
def test_generator_multicompany_1(self):
generator = self.generator.new({
'date_start': '1943-01-01',
'name_prefix': '1943-',
'type_id': self.typeB.id,
'duration_count': 3,
'unit_of_time': MONTHLY,
'count': 4,
'company_id': self.company.id,
})
generator._cache.update(generator._convert_to_cache(
{'company_id': self.company_2.id}, update=True))
generator._onchange_company_id()
self.assertFalse(generator.type_id)
def test_generator_multicompany_2(self):
with self.assertRaises(ValidationError):
self.generator.create({
'date_start': '1943-01-01',
'name_prefix': '1943-',
'type_id': self.typeB.id,
'duration_count': 3,
'unit_of_time': MONTHLY,
'count': 4,
'company_id': self.company_2.id,
})

31
date_range/tests/test_date_range_type.py

@ -5,17 +5,29 @@
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger from odoo.tools import mute_logger
from psycopg2 import IntegrityError from psycopg2 import IntegrityError
from odoo.exceptions import ValidationError
class DateRangeTypeTest(TransactionCase): class DateRangeTypeTest(TransactionCase):
def setUp(self):
super(DateRangeTypeTest, self).setUp()
self.type = self.env['date.range.type']
self.company = self.env['res.company'].create({
'name': 'Test company',
})
self.company_2 = self.env['res.company'].create({
'name': 'Test company 2',
'parent_id': self.company.id,
})
def test_default_company(self): def test_default_company(self):
drt = self.env['date.range.type'].create(
drt = self.type.create(
{'name': 'Fiscal year', {'name': 'Fiscal year',
'allow_overlap': False}) 'allow_overlap': False})
self.assertTrue(drt.company_id) self.assertTrue(drt.company_id)
# you can specify company_id to False # you can specify company_id to False
drt = self.env['date.range.type'].create(
drt = self.type.create(
{'name': 'Fiscal year', {'name': 'Fiscal year',
'company_id': False, 'company_id': False,
'allow_overlap': False}) 'allow_overlap': False})
@ -34,3 +46,18 @@ class DateRangeTypeTest(TransactionCase):
}) })
with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'): with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
drt.unlink() drt.unlink()
def test_type_multicompany(self):
drt = self.type.create(
{'name': 'Fiscal year',
'company_id': False,
'allow_overlap': False})
self.env['date.range'].create({
'name': 'FS2016',
'date_start': '2015-01-01',
'date_end': '2016-12-31',
'type_id': drt.id,
'company_id': self.company.id,
})
with self.assertRaises(ValidationError):
drt.company_id = self.company_2
Loading…
Cancel
Save