book: Feld 'start_date' + test,

line: balance-berechnung mit abstimmung gekoppelt + test,
abstimmung: start/enddatum automatisch
This commit is contained in:
Frederik Jaeckel 2022-08-18 11:58:05 +02:00
parent 5729ed0a07
commit 91a34e216b
13 changed files with 446 additions and 20 deletions

View file

@ -72,6 +72,7 @@ class BookTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'test 1',
@ -106,6 +107,7 @@ class BookTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'test 1',
@ -142,6 +144,7 @@ class BookTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'test 1',
@ -333,7 +336,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(books[0].rec_name, 'Fridas book | 0.00 usd | Open')
self.assertRaisesRegex(UserError,
'You are not allowed to access "Cashbook".',
'You are not allowed to access "Cashbook.Name".',
Book.write,
*[
books,

View file

@ -16,6 +16,124 @@ class LineTestCase(ModuleTestCase):
'Test cashbook line module'
module = 'cashbook'
@with_transaction()
def test_line_check_balance_by_line(self):
""" create cashbook, lines, reconciliations,
check calculation of balance per line
"""
pool = Pool()
Book = pool.get('cashbook.book')
Lines = pool.get('cashbook.line')
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
category = self.prep_category(cattype='in')
company = self.prep_company()
party = self.prep_party()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
'category': category.id,
'bookingtype': 'in',
'amount': Decimal('1.0'),
'party': party.id,
}, {
'date': date(2022, 5, 2),
'description': 'Text 2',
'category': category.id,
'bookingtype': 'in',
'amount': Decimal('1.0'),
'party': party.id,
}, {
'date': date(2022, 5, 15),
'description': 'Text 3',
'category': category.id,
'bookingtype': 'in',
'amount': Decimal('1.0'),
'party': party.id,
}, {
'date': date(2022, 5, 17),
'description': 'Text 4',
'category': category.id,
'bookingtype': 'in',
'amount': Decimal('1.0'),
'party': party.id,
}])],
}])
self.assertEqual(len(book.lines), 4)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].balance, Decimal('1.0'))
self.assertEqual(book.lines[0].reconciliation, None)
self.assertEqual(book.lines[0].state, 'edit')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].balance, Decimal('2.0'))
self.assertEqual(book.lines[1].reconciliation, None)
self.assertEqual(book.lines[1].state, 'edit')
self.assertEqual(book.lines[2].rec_name, '05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(book.lines[2].balance, Decimal('3.0'))
self.assertEqual(book.lines[2].reconciliation, None)
self.assertEqual(book.lines[2].state, 'edit')
self.assertEqual(book.lines[3].rec_name, '05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(book.lines[3].balance, Decimal('4.0'))
self.assertEqual(book.lines[3].reconciliation, None)
self.assertEqual(book.lines[3].state, 'edit')
Lines.wfcheck([book.lines[0], book.lines[1]])
recon, = Reconciliation.create([{
'cashbook': book.id,
}])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/02/2022 | 0.00 usd - 0.00 usd [0]')
Reconciliation.wfcheck([recon])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/02/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(len(book.lines), 4)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].balance, Decimal('1.0'))
self.assertEqual(book.lines[0].reconciliation.id, recon.id)
self.assertEqual(book.lines[0].state, 'check')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].balance, Decimal('2.0'))
self.assertEqual(book.lines[1].reconciliation.id, recon.id)
self.assertEqual(book.lines[1].state, 'check')
self.assertEqual(book.lines[2].rec_name, '05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(book.lines[2].balance, Decimal('3.0'))
self.assertEqual(book.lines[2].reconciliation, None)
self.assertEqual(book.lines[2].state, 'edit')
self.assertEqual(book.lines[3].rec_name, '05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(book.lines[3].balance, Decimal('4.0'))
self.assertEqual(book.lines[3].reconciliation, None)
self.assertEqual(book.lines[3].state, 'edit')
Reconciliation.wfdone([recon])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/02/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(len(book.lines), 4)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].balance, Decimal('1.0'))
self.assertEqual(book.lines[0].reconciliation.id, recon.id)
self.assertEqual(book.lines[0].state, 'done')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].balance, Decimal('2.0'))
self.assertEqual(book.lines[1].reconciliation.id, recon.id)
self.assertEqual(book.lines[1].state, 'done')
self.assertEqual(book.lines[2].rec_name, '05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(book.lines[2].balance, Decimal('3.0'))
self.assertEqual(book.lines[2].reconciliation, None)
self.assertEqual(book.lines[2].state, 'edit')
self.assertEqual(book.lines[3].rec_name, '05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(book.lines[3].balance, Decimal('4.0'))
self.assertEqual(book.lines[3].reconciliation, None)
self.assertEqual(book.lines[3].state, 'edit')
@with_transaction()
def test_line_create_check_names_search(self):
""" create cashbook + line
@ -34,6 +152,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -115,6 +234,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -187,6 +307,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -254,6 +375,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
}])
book, = Book.create([{
@ -262,6 +384,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Transfer Out',
@ -318,6 +441,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
}])
book, = Book.create([{
@ -326,6 +450,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Transfer In',
@ -388,6 +513,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
}])
book, = Book.create([{
@ -396,6 +522,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Revenue',
@ -531,6 +658,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -582,6 +710,7 @@ class LineTestCase(ModuleTestCase):
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'start_date': date(2022, 5, 1),
'number_sequ': self.prep_sequence().id,
'lines': [('create', [{
'date': date(2022, 5, 1),
@ -623,6 +752,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -668,6 +798,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -736,6 +867,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Test 1',
@ -817,6 +949,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Test 1',
@ -904,6 +1037,7 @@ class LineTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Test 1',

View file

@ -32,6 +32,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
}])
recon1, = Reconciliation.create([{
@ -179,6 +180,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'start_balance': Decimal('12.50'),
'start_date': date(2022, 5, 1),
'number_sequ': self.prep_sequence().id,
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
@ -211,6 +213,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'start_balance': Decimal('12.50'),
'start_date': date(2022, 5, 1),
'number_sequ': self.prep_sequence().id,
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
@ -271,6 +274,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
@ -293,6 +297,56 @@ class ReconTestCase(ModuleTestCase):
Reconciliation.wfcheck,
recons)
@with_transaction()
def test_recon_autoset_date_to(self):
""" create reconciliation, check: set date_to to last date of checked-line
"""
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
company = self.prep_company()
party = self.prep_party()
category = self.prep_category(cattype='in')
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 5),
'amount': Decimal('10.0'),
'bookingtype': 'in',
'party': party.id,
'category': category.id,
}, {
'date': date(2022, 5, 18),
'amount': Decimal('5.0'),
'bookingtype': 'in',
'party': party.id,
'category': category.id,
}])],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.state, 'open')
Line.wfcheck(list(book.lines))
recon, = Reconciliation.create([{
'cashbook': book.id,
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 5),
'date_to': date(2022, 5, 31),
}])
# dates are updates by .create()
self.assertEqual(recon.rec_name, '05/01/2022 - 05/18/2022 | 0.00 usd - 0.00 usd [0]')
Reconciliation.wfcheck([recon])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/18/2022 | 0.00 usd - 15.00 usd [2]')
@with_transaction()
def test_recon_autoset_date_from(self):
""" create reconciliation, check: set date_from to end of predecessor
@ -309,9 +363,10 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
'date_from': date(2022, 5, 5),
'date_to': date(2022, 5, 31),
}])],
}])
@ -320,6 +375,10 @@ class ReconTestCase(ModuleTestCase):
Reconciliation.wfcheck([book.reconciliations[0]])
Reconciliation.wfdone([book.reconciliations[0]])
# date_from is corrected by .create() to start_date of book
self.assertEqual(book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
r2, = Reconciliation.create([{
'cashbook': book.id,
'date_from': date(2022, 6, 10),
@ -359,6 +418,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -500,6 +560,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -562,6 +623,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
@ -625,6 +687,7 @@ class ReconTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',