kategorie: sperrt 'Typ' wenn parent existiert, korrekte Anpassung

der sub-kategorien bei Änderung + test
Line: Kategoriefeld prüft Inhalt + tests
This commit is contained in:
Frederik Jaeckel 2022-08-11 11:06:28 +02:00
parent 52ffa0536e
commit 8fd6e0d339
7 changed files with 137 additions and 46 deletions

View file

@ -43,7 +43,7 @@ class BookTestCase(ModuleTestCase):
Book = pool.get('cashbook.book')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -74,7 +74,7 @@ class BookTestCase(ModuleTestCase):
Book = pool.get('cashbook.book')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -107,7 +107,7 @@ class BookTestCase(ModuleTestCase):
Book = pool.get('cashbook.book')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',

View file

@ -13,7 +13,7 @@ class CategoryTestCase(ModuleTestCase):
'Test cashbook categoy module'
module = 'cashbook'
def prep_category(self, name='Cat1'):
def prep_category(self, name='Cat1', cattype='out'):
""" create category
"""
pool = Pool()
@ -24,9 +24,57 @@ class CategoryTestCase(ModuleTestCase):
category, = Category.create([{
'company': company.id,
'name': name,
'cattype': cattype,
}])
return category
@with_transaction()
def test_category_create_check_category_type(self):
""" create category, update type of category
"""
pool = Pool()
Category = pool.get('cashbook.category')
company = self.prep_company()
category, = Category.create([{
'company': company.id,
'name': 'Level 1',
'cattype': 'in',
'childs': [('create', [{
'company': company.id,
'name': 'Level 2',
'cattype': 'in',
}])],
}])
self.assertEqual(category.rec_name, 'Level 1')
self.assertEqual(category.cattype, 'in')
self.assertEqual(len(category.childs), 1)
self.assertEqual(category.childs[0].rec_name, 'Level 1/Level 2')
self.assertEqual(category.childs[0].cattype, 'in')
self.assertRaisesRegex(UserError,
'The value for field "Type" in "Category" is not valid according to its domain.',
Category.write,
*[
[category.childs[0]],
{
'cattype': 'out',
},
])
Category.write(*[
[category],
{
'cattype': 'out',
}])
self.assertEqual(category.rec_name, 'Level 1')
self.assertEqual(category.cattype, 'out')
self.assertEqual(len(category.childs), 1)
self.assertEqual(category.childs[0].rec_name, 'Level 1/Level 2')
self.assertEqual(category.childs[0].cattype, 'out')
@with_transaction()
def test_category_create_nodupl_at_root(self):
""" create category, duplicates are allowed at root-level

View file

@ -25,7 +25,7 @@ class LineTestCase(ModuleTestCase):
Lines = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -102,7 +102,7 @@ class LineTestCase(ModuleTestCase):
Line = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -150,7 +150,7 @@ class LineTestCase(ModuleTestCase):
IrDate = pool.get('ir.date')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
IrDate.today = MagicMock(return_value=date(2022, 6, 1))
@ -214,14 +214,10 @@ class LineTestCase(ModuleTestCase):
Category = pool.get('cashbook.category')
types = self.prep_type()
category = self.prep_category()
category_in = self.prep_category(cattype='in')
category_out = self.prep_category(name='Out Category', cattype='out')
company = self.prep_company()
category2, = Category.create([{
'company': company.id,
'name': 'Category',
}])
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
@ -230,25 +226,25 @@ class LineTestCase(ModuleTestCase):
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Revenue',
'category': category2.id,
'category': category_in.id,
'bookingtype': 'in',
'amount': Decimal('1.0'),
}, {
'date': date(2022, 6, 1),
'description': 'Expense',
'category': category2.id,
'category': category_out.id,
'bookingtype': 'out',
'amount': Decimal('1.0'),
}, {
'date': date(2022, 6, 1),
'description': 'Transfer from',
'category': category2.id,
'category': category_in.id,
'bookingtype': 'mvin',
'amount': Decimal('1.0'),
}, {
'date': date(2022, 6, 1),
'description': 'Transfer to',
'category': category2.id,
'category': category_out.id,
'bookingtype': 'mvout',
'amount': Decimal('1.0'),
}])],
@ -291,6 +287,7 @@ class LineTestCase(ModuleTestCase):
[book.lines[0]],
{
'bookingtype': 'out',
'category': category_out.id,
}])
self.assertEqual(book.lines[0].amount, Decimal('2.0'))
self.assertEqual(book.lines[0].bookingtype, 'out')
@ -300,6 +297,7 @@ class LineTestCase(ModuleTestCase):
Line.write(*[
[book.lines[0]],
{
'category': category_in.id,
'bookingtype': 'mvin',
'amount': Decimal('3.0'),
}])
@ -320,7 +318,7 @@ class LineTestCase(ModuleTestCase):
Account = pool.get('account.account')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
with Transaction().set_context({
@ -340,10 +338,12 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'name': 'Level1',
'account': accounts[0].id,
'cattype': 'in',
'childs': [('create', [{
'company': company.id,
'name': 'Level2',
'account': accounts[1].id,
'cattype': 'in',
}])],
}])
self.assertEqual(category2.rec_name, 'Level1 [0123]')
@ -414,7 +414,7 @@ class LineTestCase(ModuleTestCase):
Lines = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -450,7 +450,7 @@ class LineTestCase(ModuleTestCase):
Lines = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -491,7 +491,7 @@ class LineTestCase(ModuleTestCase):
Lines = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -536,7 +536,7 @@ class LineTestCase(ModuleTestCase):
Line = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
usr_lst = ResUser.create([{
@ -606,7 +606,7 @@ class LineTestCase(ModuleTestCase):
Line = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
grp_reviewer, = ResGroup.create([{
@ -690,7 +690,7 @@ class LineTestCase(ModuleTestCase):
Line = pool.get('cashbook.line')
types = self.prep_type()
category = self.prep_category()
category = self.prep_category(cattype='in')
company = self.prep_company()
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
grp_observer, = ResGroup.create([{