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
|
@ -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'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue