line: datumsbereich prüfen + test,

abstimmung: vorgänger beachten + test
line: party/transfer-book + test muß noch
This commit is contained in:
Frederik Jaeckel 2022-08-15 17:19:53 +02:00
parent 7a07da852d
commit 30b91cf518
8 changed files with 465 additions and 28 deletions

View file

@ -47,15 +47,10 @@ class ReconTestCase(ModuleTestCase):
'date_to': date(2022, 6, 30),
'cashbook': book.id,
}])
self.assertEqual(recon2.rec_name, '06/01/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
# updated by create to date_to of predecessor
self.assertEqual(recon2.rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
# same day for end of '0' and start of '1'
Reconciliation.write(*[
[recon2],
{
'date_from': date(2022, 5, 31),
},
])
self.assertEqual(recon1.rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(recon2.rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
@ -146,7 +141,7 @@ class ReconTestCase(ModuleTestCase):
},
])
# overlap at create
# overlap at .create()
self.assertRaisesRegex(UserError,
'The date range overlaps with another reconciliation.',
Reconciliation.create,
@ -159,13 +154,183 @@ class ReconTestCase(ModuleTestCase):
recon3, = Reconciliation.create([{
'date': date(2022, 4, 17),
'date_from': date(2022, 4, 1),
'date_to': date(2022, 4, 15),
'date_from': date(2022, 6, 1),
'date_to': date(2022, 6, 15),
'cashbook': book.id,
}])
self.assertEqual(recon1.rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(recon2.rec_name, '04/15/2022 - 05/01/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(recon3.rec_name, '04/01/2022 - 04/15/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(recon3.rec_name, '05/31/2022 - 06/15/2022 | 0.00 usd - 0.00 usd [0]')
@with_transaction()
def test_recon_set_start_amount_by_cashbook(self):
""" set stat-amount from cashbook-setting
"""
pool = Pool()
Book = pool.get('cashbook.book')
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'start_balance': Decimal('12.50'),
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31),
}])],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 12.50 usd - 12.50 usd [0]')
@with_transaction()
def test_recon_set_start_amount_by_predecessor(self):
""" set stat-amount from end_amount of predecessor
"""
pool = Pool()
Book = pool.get('cashbook.book')
Lines = pool.get('cashbook.line')
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
company = self.prep_company()
category = self.prep_category(cattype='in')
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'start_balance': Decimal('12.50'),
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31),
}])],
'lines': [('create', [{
'date': date(2022, 5, 5),
'bookingtype': 'in',
'category': category.id,
'description': 'Line 1',
'amount': Decimal('5.0'),
}, {
'date': date(2022, 5, 5),
'bookingtype': 'in',
'category': category.id,
'description': 'Line 2',
'amount': Decimal('7.0'),
},])],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(len(book.reconciliations), 1)
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(len(book.reconciliations[0].lines), 0)
Lines.wfcheck(list(book.lines))
Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].state, 'check')
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 12.50 usd - 24.50 usd [2]')
Reconciliation.wfdone(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].state, 'done')
recons = Reconciliation.create([{
'cashbook': book.id,
'date_from': date(2022, 5, 31),
'date_to': date(2022, 6, 30),
}])
self.assertEqual(recons[0].rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
Reconciliation.wfcheck(recons)
self.assertEqual(recons[0].rec_name, '05/31/2022 - 06/30/2022 | 24.50 usd - 24.50 usd [0]')
@with_transaction()
def test_recon_predecessor_done(self):
""" predecessor must be done
"""
pool = Pool()
Book = pool.get('cashbook.book')
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31),
}])],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.state, 'open')
Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(book.reconciliations[0].state, 'check')
recons = Reconciliation.create([{
'cashbook': book.id,
'date_from': date(2022, 5, 31),
'date_to': date(2022, 6, 30),
}])
self.assertRaisesRegex(UserError,
"The predecessor '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]' must be in the 'Done' state before you can check the current reconciliation '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]'.",
Reconciliation.wfcheck,
recons)
@with_transaction()
def test_recon_autoset_date_from(self):
""" create reconciliation, check: set date_from to end of predecessor
"""
pool = Pool()
Book = pool.get('cashbook.book')
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31),
}])],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.state, 'open')
Reconciliation.wfcheck([book.reconciliations[0]])
Reconciliation.wfdone([book.reconciliations[0]])
r2, = Reconciliation.create([{
'cashbook': book.id,
'date_from': date(2022, 6, 10),
'date_to': date(2022, 6, 30),
}])
self.assertEqual(r2.rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
# update 'date_from' to wrong value
Reconciliation.write(*[
[r2],
{
'date_from': date(2022, 6, 1),
}])
self.assertEqual(r2.rec_name, '06/01/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertRaisesRegex(UserError,
"The start date '06/01/2022' of the current reconciliation '06/01/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]' must correspond to the end date '05/31/2022' of the predecessor.",
Reconciliation.wfcheck,
[r2])
@with_transaction()
def test_recon_create_check_line_add_to_recon(self):
@ -235,6 +400,133 @@ class ReconTestCase(ModuleTestCase):
Lines.wfedit,
[book.lines[0]])
# unlink lines from reconciliation
self.assertEqual(book.reconciliations[0].state, 'edit')
self.assertEqual(len(book.reconciliations[0].lines), 2)
Reconciliation.wfcheck(list(book.reconciliations))
Reconciliation.wfedit(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].state, 'edit')
self.assertEqual(len(book.reconciliations[0].lines), 0)
# move date of 2nd line to june 1
# set reconciliation to 'check'
Lines.wfedit([book.lines[1]])
Lines.write(*[
[book.lines[1]],
{
'date': date(2022, 6, 1),
}])
# check reconciliation, this linkes the 1st line by date
Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].state, 'check')
self.assertEqual(len(book.reconciliations[0].lines), 1)
self.assertEqual(book.reconciliations[0].lines[0].rec_name, '05/01/2022|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].rec_name, '05/01/2022|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[1].rec_name, '06/01/2022|1.00 usd|Text 2 [Cat1]')
# move 2nd line into date-range of checked-reconciliation, wf-check
Lines.write(*[
[book.lines[1]],
{
'date': date(2022, 5, 20),
}])
self.assertRaisesRegex(UserError,
"For the date '05/20/2022' there is already a completed reconciliation. Use a different date.",
Lines.wfcheck,
[book.lines[1]])
# set date to end of date-range of reconciliation
# should work
Lines.write(*[
[book.lines[1]],
{
'date': date(2022, 5, 31),
}])
Lines.wfcheck([book.lines[1]]) # ok
Lines.wfedit([book.lines[1]])
Lines.write(*[
[book.lines[1]],
{
'date': date(2022, 7, 1),
}])
# add 2nd reconciliation
recon2, = Reconciliation.create([{
'cashbook': book.id,
'date_from': date(2022, 5, 31),
'date_to': date(2022, 6, 30),
}])
Reconciliation.wfdone([book.reconciliations[0]])
Reconciliation.wfcheck([recon2])
Lines.write(*[
[book.lines[1]],
{
'date': date(2022, 5, 31),
}])
self.assertRaisesRegex(UserError,
"For the date '05/31/2022' there is already a completed reconciliation. Use a different date.",
Lines.wfcheck,
[book.lines[1]])
@with_transaction()
def test_recon_check_wfcheck_missing_lines(self):
""" create, booklines, check missing line at wfcheck
"""
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()
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, 5),
'description': 'Text 2',
'category': category.id,
'bookingtype': 'in',
'amount': Decimal('1.0'),
}])],
'reconciliations': [('create', [{
'date': date(2022, 5, 28),
'date_from': date(2022, 5, 1),
'date_to': date(2022, 5, 31),
}])],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.state, 'open')
self.assertEqual(len(book.lines), 2)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[1].rec_name, '06/05/2022|1.00 usd|Text 2 [Cat1]')
Lines.wfcheck([book.lines[0]])
Reconciliation.wfcheck([book.reconciliations[0]])
self.assertEqual(len(book.reconciliations[0].lines), 1)
self.assertEqual(book.reconciliations[0].lines[0].rec_name, '05/01/2022|1.00 usd|Text 1 [Cat1]')
Lines.write(*[
[book.lines[1]],
{
'date': date(2022, 5, 15),
}])
self.assertRaisesRegex(UserError,
"In the date range from 05/01/2022 to 05/31/2022, there are still cashbook lines that do not belong to any reconciliation.",
Reconciliation.wfdone,
[book.reconciliations[0]])
@with_transaction()
def test_recon_check_deny_delete(self):
""" create, booklines, reconciliation, try delete
@ -353,8 +645,8 @@ class ReconTestCase(ModuleTestCase):
Lines.wfcheck(book.lines)
Reconciliation.wfcheck(list(book.reconciliations))
self.assertEqual(len(book.reconciliations[0].lines), 2)
self.assertEqual(book.lines[0].reconciliation.rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [2]')
self.assertEqual(book.lines[1].reconciliation.rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [2]')
self.assertEqual(book.lines[0].reconciliation.rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(book.lines[1].reconciliation.rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 2.00 usd [2]')
# check --> edit
Reconciliation.wfedit(list(book.reconciliations))