test ergänzt
This commit is contained in:
parent
c69b9c86d8
commit
521b9c290c
1 changed files with 81 additions and 0 deletions
|
@ -14,4 +14,85 @@ class CategoryTestCase(CashbookTestCase):
|
|||
'Test cashbook category module'
|
||||
module = 'cashbook_bookcategory'
|
||||
|
||||
@with_transaction()
|
||||
def test_bookcategory_create(self):
|
||||
""" add categories
|
||||
"""
|
||||
BookCategory = Pool().get('cashbook.bookcategory')
|
||||
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
categories, = BookCategory.create([{
|
||||
'name': 'Cat 0',
|
||||
'childs': [('create', [{
|
||||
'name': 'Cat 1'
|
||||
}, {
|
||||
'name': 'Cat 2'
|
||||
}])],
|
||||
}])
|
||||
|
||||
cat2 = BookCategory.search([])
|
||||
self.assertEqual(len(cat2), 3)
|
||||
self.assertEqual(cat2[0].rec_name, 'Cat 0')
|
||||
self.assertEqual(cat2[1].rec_name, 'Cat 0 / Cat 1')
|
||||
self.assertEqual(cat2[2].rec_name, 'Cat 0 / Cat 2')
|
||||
|
||||
# delete single category
|
||||
BookCategory.delete([cat2[2]])
|
||||
|
||||
# delete tree
|
||||
BookCategory.delete([cat2[0]])
|
||||
|
||||
@with_transaction()
|
||||
def test_bookcategory_add_to_cashbook(self):
|
||||
""" add categories, link to cashbook
|
||||
"""
|
||||
pool = Pool()
|
||||
BookCategory = pool.get('cashbook.bookcategory')
|
||||
Book = pool.get('cashbook.book')
|
||||
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
category, = BookCategory.create([{
|
||||
'name': 'Cat 0',
|
||||
'childs': [('create', [{
|
||||
'name': 'Cat 1'
|
||||
}, {
|
||||
'name': 'Cat 2'
|
||||
}])],
|
||||
}])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'categories': [('add', [category.id])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
|
||||
self.assertEqual(len(book.categories), 1)
|
||||
self.assertEqual(book.categories[0].rec_name, 'Cat 0')
|
||||
|
||||
# replace category
|
||||
Book.write(*[
|
||||
[book],
|
||||
{
|
||||
'categories': [
|
||||
('remove', [category.id]),
|
||||
('add', [category.childs[0].id]),
|
||||
],
|
||||
}])
|
||||
self.assertEqual(len(book.categories), 1)
|
||||
self.assertEqual(book.categories[0].rec_name, 'Cat 0 / Cat 1')
|
||||
|
||||
# delete all categories, this will unlink it from cashbook
|
||||
BookCategory.delete([category])
|
||||
|
||||
self.assertEqual(len(book.categories), 0)
|
||||
|
||||
# end CategoryTestCase
|
||||
|
|
Loading…
Reference in a new issue