book, line, category, types: berechtigung für company-user + test,
book: währung neu, line: buchungstyp, betrag, credit, debit, währung, sortierung
This commit is contained in:
parent
1a85b8e80e
commit
d57d76ba3b
20 changed files with 620 additions and 115 deletions
|
@ -8,6 +8,7 @@ from trytond.pool import Pool
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class BookTestCase(ModuleTestCase):
|
||||
|
@ -20,13 +21,14 @@ class BookTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.btype.rec_name, 'CAS - Cash')
|
||||
|
@ -39,18 +41,21 @@ class BookTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'test 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -67,18 +72,21 @@ class BookTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'test 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -97,18 +105,21 @@ class BookTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'test 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -125,13 +136,14 @@ class BookTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
|
@ -188,18 +200,22 @@ class BookTestCase(ModuleTestCase):
|
|||
ResUser = pool.get('res.user')
|
||||
ResGroup = pool.get('res.group')
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
usr_lst = ResUser.create([{
|
||||
'login': 'frida',
|
||||
'name': 'Frida',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}, {
|
||||
'login': 'diego',
|
||||
'name': 'Diego',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(len(usr_lst), 2)
|
||||
self.assertEqual(usr_lst[0].name, 'Frida')
|
||||
|
@ -209,6 +225,8 @@ class BookTestCase(ModuleTestCase):
|
|||
'name': 'Fridas book',
|
||||
'owner': usr_lst[0].id,
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
self.assertEqual(book.owner.rec_name, 'Frida'),
|
||||
|
@ -245,9 +263,9 @@ class BookTestCase(ModuleTestCase):
|
|||
ResUser = pool.get('res.user')
|
||||
ResGroup = pool.get('res.group')
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
grp_reviewer, = ResGroup.create([{
|
||||
'name': 'Cashbook Reviewer',
|
||||
|
@ -257,10 +275,14 @@ class BookTestCase(ModuleTestCase):
|
|||
'login': 'frida',
|
||||
'name': 'Frida',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}, {
|
||||
'login': 'diego',
|
||||
'name': 'Diego',
|
||||
'groups': [('add', [grp_cashbook.id, grp_reviewer.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(len(usr_lst), 2)
|
||||
self.assertEqual(usr_lst[0].name, 'Frida')
|
||||
|
@ -272,6 +294,8 @@ class BookTestCase(ModuleTestCase):
|
|||
'name': 'Fridas book',
|
||||
'owner': usr_lst[0].id,
|
||||
'reviewer': grp_reviewer.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'btype': types.id,
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
@ -301,9 +325,9 @@ class BookTestCase(ModuleTestCase):
|
|||
ResUser = pool.get('res.user')
|
||||
ResGroup = pool.get('res.group')
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
grp_observer, = ResGroup.create([{
|
||||
'name': 'Cashbook Observer',
|
||||
|
@ -313,10 +337,14 @@ class BookTestCase(ModuleTestCase):
|
|||
'login': 'frida',
|
||||
'name': 'Frida',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}, {
|
||||
'login': 'diego',
|
||||
'name': 'Diego',
|
||||
'groups': [('add', [grp_cashbook.id, grp_observer.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(len(usr_lst), 2)
|
||||
self.assertEqual(usr_lst[0].name, 'Frida')
|
||||
|
@ -328,6 +356,8 @@ class BookTestCase(ModuleTestCase):
|
|||
'name': 'Fridas book',
|
||||
'owner': usr_lst[0].id,
|
||||
'observer': grp_observer.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'btype': types.id,
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
|
|
@ -7,7 +7,6 @@ from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
|||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.company.tests import create_company
|
||||
|
||||
|
||||
class CategoryTestCase(ModuleTestCase):
|
||||
|
@ -21,12 +20,7 @@ class CategoryTestCase(ModuleTestCase):
|
|||
Company = pool.get('company.company')
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = Company.search([])
|
||||
if len(company) > 0:
|
||||
company = company[0]
|
||||
else :
|
||||
company = create_company(name='m-ds')
|
||||
|
||||
company = self.prep_company()
|
||||
category, = Category.create([{
|
||||
'company': company.id,
|
||||
'name': name,
|
||||
|
@ -40,7 +34,7 @@ class CategoryTestCase(ModuleTestCase):
|
|||
pool = Pool()
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
company = self.prep_company()
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
|
@ -73,7 +67,7 @@ class CategoryTestCase(ModuleTestCase):
|
|||
pool = Pool()
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
company = self.prep_company()
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
|
@ -100,7 +94,7 @@ class CategoryTestCase(ModuleTestCase):
|
|||
pool = Pool()
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
company = self.prep_company()
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
|
@ -126,7 +120,7 @@ class CategoryTestCase(ModuleTestCase):
|
|||
Account = pool.get('account.account')
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
company = create_company(name='m-ds')
|
||||
company = self.prep_company()
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
|
|
|
@ -7,6 +7,7 @@ from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
|||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.company.tests import create_company
|
||||
from datetime import date
|
||||
|
||||
|
||||
|
@ -14,6 +15,18 @@ class ConfigTestCase(ModuleTestCase):
|
|||
'Test config type module'
|
||||
module = 'cashbook'
|
||||
|
||||
def prep_company(self):
|
||||
""" get/create company
|
||||
"""
|
||||
Company = Pool().get('company.company')
|
||||
|
||||
company = Company.search([])
|
||||
if len(company) > 0:
|
||||
company = company[0]
|
||||
else :
|
||||
company = create_company(name='m-ds')
|
||||
return company
|
||||
|
||||
@with_transaction()
|
||||
def test_config_create(self):
|
||||
""" create config
|
||||
|
|
|
@ -9,6 +9,7 @@ from trytond.transaction import Transaction
|
|||
from trytond.exceptions import UserError
|
||||
from datetime import date
|
||||
from unittest.mock import MagicMock
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class LineTestCase(ModuleTestCase):
|
||||
|
@ -21,23 +22,28 @@ class LineTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -59,29 +65,62 @@ class LineTestCase(ModuleTestCase):
|
|||
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'open')]), 2)
|
||||
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'closed')]), 0)
|
||||
|
||||
# sorting: date -> state -> id
|
||||
self.assertEqual(len(book.lines), 2)
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022 Text 1')
|
||||
self.assertEqual(book.lines[0].state, 'edit')
|
||||
self.assertEqual(book.lines[1].rec_name, '05/02/2022 Text 2')
|
||||
self.assertEqual(book.lines[1].state, 'edit')
|
||||
|
||||
# set to same date
|
||||
Lines.write(*[
|
||||
list(book.lines),
|
||||
{
|
||||
'date': date(2022, 5, 1),
|
||||
}])
|
||||
# check again
|
||||
book, = Book.search([])
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022 Text 1')
|
||||
self.assertEqual(book.lines[0].state, 'edit')
|
||||
self.assertEqual(book.lines[1].rec_name, '05/01/2022 Text 2')
|
||||
self.assertEqual(book.lines[1].state, 'edit')
|
||||
|
||||
# set to 'check', will sort first
|
||||
Lines.wfcheck([book.lines[1]])
|
||||
book, = Book.search([])
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022 Text 2')
|
||||
self.assertEqual(book.lines[0].state, 'check')
|
||||
self.assertEqual(book.lines[1].rec_name, '05/01/2022 Text 1')
|
||||
self.assertEqual(book.lines[1].state, 'edit')
|
||||
|
||||
@with_transaction()
|
||||
def test_line_create_check_deny_write(self):
|
||||
""" create cashbook + line, 'close' book, write to line
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Line = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -107,26 +146,31 @@ class LineTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Line = pool.get('cashbook.line')
|
||||
IrDate = pool.get('ir.date')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
IrDate.today = MagicMock(return_value=date(2022, 6, 1))
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -159,21 +203,125 @@ class LineTestCase(ModuleTestCase):
|
|||
|
||||
IrDate.today = MagicMock(return_value=date.today())
|
||||
|
||||
@with_transaction()
|
||||
def test_line_create_check_debit_credit(self):
|
||||
""" create cashbook + line, check calculation of debit/credit
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
Configuration = pool.get('cashbook.configuration')
|
||||
Category = pool.get('cashbook.category')
|
||||
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
company = self.prep_company()
|
||||
|
||||
category2, = Category.create([{
|
||||
'company': company.id,
|
||||
'name': 'Category',
|
||||
}])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Revenue',
|
||||
'category': category2.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Expense',
|
||||
'category': category2.id,
|
||||
'bookingtype': 'out',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Transfer from',
|
||||
'category': category2.id,
|
||||
'bookingtype': 'mvin',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Transfer to',
|
||||
'category': category2.id,
|
||||
'bookingtype': 'mvout',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
self.assertEqual(len(book.lines), 4)
|
||||
|
||||
self.assertEqual(book.lines[0].amount, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[0].bookingtype, 'in')
|
||||
self.assertEqual(book.lines[0].credit, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[0].debit, Decimal('0.0'))
|
||||
|
||||
self.assertEqual(book.lines[1].amount, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[1].bookingtype, 'out')
|
||||
self.assertEqual(book.lines[1].credit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[1].debit, Decimal('1.0'))
|
||||
|
||||
self.assertEqual(book.lines[2].amount, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[2].bookingtype, 'mvin')
|
||||
self.assertEqual(book.lines[2].credit, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[2].debit, Decimal('0.0'))
|
||||
|
||||
self.assertEqual(book.lines[3].amount, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[3].bookingtype, 'mvout')
|
||||
self.assertEqual(book.lines[3].credit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[3].debit, Decimal('1.0'))
|
||||
|
||||
Line.write(*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'amount': Decimal('2.0'),
|
||||
}])
|
||||
self.assertEqual(book.lines[0].amount, Decimal('2.0'))
|
||||
self.assertEqual(book.lines[0].bookingtype, 'in')
|
||||
self.assertEqual(book.lines[0].credit, Decimal('2.0'))
|
||||
self.assertEqual(book.lines[0].debit, Decimal('0.0'))
|
||||
|
||||
Line.write(*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'bookingtype': 'out',
|
||||
}])
|
||||
self.assertEqual(book.lines[0].amount, Decimal('2.0'))
|
||||
self.assertEqual(book.lines[0].bookingtype, 'out')
|
||||
self.assertEqual(book.lines[0].credit, Decimal('0.0'))
|
||||
self.assertEqual(book.lines[0].debit, Decimal('2.0'))
|
||||
|
||||
Line.write(*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'bookingtype': 'mvin',
|
||||
'amount': Decimal('3.0'),
|
||||
}])
|
||||
self.assertEqual(book.lines[0].amount, Decimal('3.0'))
|
||||
self.assertEqual(book.lines[0].bookingtype, 'mvin')
|
||||
self.assertEqual(book.lines[0].credit, Decimal('3.0'))
|
||||
self.assertEqual(book.lines[0].debit, Decimal('0.0'))
|
||||
|
||||
@with_transaction()
|
||||
def test_line_create_check_category_view(self):
|
||||
""" create cashbook + line, check 'category_view'
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Line = pool.get('cashbook.line')
|
||||
Configuration = pool.get('cashbook.configuration')
|
||||
Category = pool.get('cashbook.category')
|
||||
Account = pool.get('account.account')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
company = category.company
|
||||
company = self.prep_company()
|
||||
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
|
@ -208,14 +356,20 @@ class LineTestCase(ModuleTestCase):
|
|||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category2.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Text 2',
|
||||
'category': category2.childs[0].id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -257,23 +411,28 @@ class LineTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -288,23 +447,28 @@ class LineTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -324,23 +488,28 @@ class LineTestCase(ModuleTestCase):
|
|||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
|
||||
company = self.prep_company()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -365,19 +534,23 @@ class LineTestCase(ModuleTestCase):
|
|||
ResGroup = pool.get('res.group')
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
company = self.prep_company()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
usr_lst = ResUser.create([{
|
||||
'login': 'frida',
|
||||
'name': 'Frida',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}, {
|
||||
'login': 'diego',
|
||||
'name': 'Diego',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(len(usr_lst), 2)
|
||||
self.assertEqual(usr_lst[0].name, 'Frida')
|
||||
|
@ -387,10 +560,14 @@ class LineTestCase(ModuleTestCase):
|
|||
'name': 'Fridas book',
|
||||
'owner': usr_lst[0].id,
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Test 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
@ -427,10 +604,10 @@ class LineTestCase(ModuleTestCase):
|
|||
ResGroup = pool.get('res.group')
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
company = self.prep_company()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
grp_reviewer, = ResGroup.create([{
|
||||
'name': 'Cashbook Reviewer',
|
||||
|
@ -440,10 +617,14 @@ class LineTestCase(ModuleTestCase):
|
|||
'login': 'frida',
|
||||
'name': 'Frida',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}, {
|
||||
'login': 'diego',
|
||||
'name': 'Diego',
|
||||
'groups': [('add', [grp_cashbook.id, grp_reviewer.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(len(usr_lst), 2)
|
||||
self.assertEqual(usr_lst[0].name, 'Frida')
|
||||
|
@ -456,10 +637,14 @@ class LineTestCase(ModuleTestCase):
|
|||
'owner': usr_lst[0].id,
|
||||
'reviewer': grp_reviewer.id,
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Test 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
@ -503,10 +688,10 @@ class LineTestCase(ModuleTestCase):
|
|||
ResGroup = pool.get('res.group')
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
types = self.prep_type()
|
||||
category = self.prep_category()
|
||||
company = self.prep_company()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
grp_observer, = ResGroup.create([{
|
||||
'name': 'Cashbook Observer',
|
||||
|
@ -516,10 +701,14 @@ class LineTestCase(ModuleTestCase):
|
|||
'login': 'frida',
|
||||
'name': 'Frida',
|
||||
'groups': [('add', [grp_cashbook.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}, {
|
||||
'login': 'diego',
|
||||
'name': 'Diego',
|
||||
'groups': [('add', [grp_cashbook.id, grp_observer.id])],
|
||||
'companies': [('add', [company.id])],
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(len(usr_lst), 2)
|
||||
self.assertEqual(usr_lst[0].name, 'Frida')
|
||||
|
@ -532,10 +721,14 @@ class LineTestCase(ModuleTestCase):
|
|||
'owner': usr_lst[0].id,
|
||||
'observer': grp_observer.id,
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Test 1',
|
||||
'category': category.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
|
|
@ -13,17 +13,20 @@ class TypeTestCase(ModuleTestCase):
|
|||
'Test cashbook type module'
|
||||
module = 'cashbook'
|
||||
|
||||
@with_transaction()
|
||||
def test_type_read_existing(self):
|
||||
""" read predefined types
|
||||
def prep_type(self, name='Cash', short='CAS'):
|
||||
""" create book-type
|
||||
"""
|
||||
AccType = Pool().get('cashbook.type')
|
||||
|
||||
t_lst = AccType.search([], order=[('name', 'ASC')])
|
||||
self.assertEqual(len(t_lst), 3)
|
||||
self.assertEqual(t_lst[0].rec_name, 'CAS - Cash')
|
||||
self.assertEqual(t_lst[1].rec_name, 'FTD - Fixed-term deposit')
|
||||
self.assertEqual(t_lst[2].rec_name, 'GIR - Giro')
|
||||
company = self.prep_company()
|
||||
at, = AccType.create([{
|
||||
'name': name,
|
||||
'short': short,
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(at.name, name)
|
||||
self.assertEqual(at.short, short)
|
||||
return at
|
||||
|
||||
@with_transaction()
|
||||
def test_type_create(self):
|
||||
|
@ -31,9 +34,12 @@ class TypeTestCase(ModuleTestCase):
|
|||
"""
|
||||
AccType = Pool().get('cashbook.type')
|
||||
|
||||
company = self.prep_company()
|
||||
|
||||
at, = AccType.create([{
|
||||
'name': 'Test 1',
|
||||
'short': 'T1',
|
||||
'company': company.id,
|
||||
}])
|
||||
self.assertEqual(at.name, 'Test 1')
|
||||
self.assertEqual(at.short, 'T1')
|
||||
|
@ -45,6 +51,7 @@ class TypeTestCase(ModuleTestCase):
|
|||
[{
|
||||
'name': 'Test 2',
|
||||
'short': 'T1',
|
||||
'company': company.id,
|
||||
}])
|
||||
|
||||
# end TypeTestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue