cashbooks, types, currenciews - verknüpfung+löschen+test
This commit is contained in:
parent
085228e047
commit
01470569e7
9 changed files with 429 additions and 22 deletions
|
@ -22,16 +22,18 @@ class ReportTestCase(CashbookTestCase):
|
|||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
|
||||
types = self.prep_type()
|
||||
type_cash = self.prep_type()
|
||||
type_bank = self.prep_type(name='Bank', short='BK')
|
||||
company = self.prep_company()
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
sequ_id = self.prep_sequence().id
|
||||
category = self.prep_category(cattype='in')
|
||||
party = self.prep_party()
|
||||
books = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'btype': type_cash.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': sequ_id,
|
||||
'start_date': date(2022, 4, 1),
|
||||
'lines': [('create', [{
|
||||
|
@ -51,9 +53,9 @@ class ReportTestCase(CashbookTestCase):
|
|||
}])],
|
||||
}, {
|
||||
'name': 'Book 2',
|
||||
'btype': types.id,
|
||||
'btype': type_cash.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': sequ_id,
|
||||
'start_date': date(2022, 4, 1),
|
||||
'lines': [('create', [{
|
||||
|
@ -73,9 +75,9 @@ class ReportTestCase(CashbookTestCase):
|
|||
}])],
|
||||
}, {
|
||||
'name': 'Book 3',
|
||||
'btype': types.id,
|
||||
'btype': type_bank.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': sequ_id,
|
||||
'start_date': date(2022, 4, 1),
|
||||
'lines': [('create', [{
|
||||
|
@ -96,22 +98,120 @@ class ReportTestCase(CashbookTestCase):
|
|||
}])
|
||||
self.assertEqual(len(books), 3)
|
||||
self.assertEqual(books[0].name, 'Book 1')
|
||||
self.assertEqual(books[0].btype.rec_name, 'CAS - Cash')
|
||||
self.assertEqual(len(books[0].lines), 2)
|
||||
self.assertEqual(books[0].balance, Decimal('25.0'))
|
||||
|
||||
self.assertEqual(books[1].name, 'Book 2')
|
||||
self.assertEqual(books[1].btype.rec_name, 'CAS - Cash')
|
||||
self.assertEqual(len(books[1].lines), 2)
|
||||
self.assertEqual(books[1].balance, Decimal('12.5'))
|
||||
|
||||
self.assertEqual(books[2].name, 'Book 3')
|
||||
self.assertEqual(books[2].btype.rec_name, 'BK - Bank')
|
||||
self.assertEqual(len(books[2].lines), 2)
|
||||
self.assertEqual(books[2].balance, Decimal('23.0'))
|
||||
return books
|
||||
|
||||
@with_transaction()
|
||||
def test_report_dtype_update(self):
|
||||
""" check unlink of cashbooks/types/currenciews
|
||||
"""
|
||||
pool = Pool()
|
||||
Evaluation = pool.get('cashbook_report.evaluation')
|
||||
Types = pool.get('cashbook.type')
|
||||
Currency = pool.get('currency.currency')
|
||||
|
||||
books = self.prep_report_3books()
|
||||
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
# valid
|
||||
evaluation, = Evaluation.create([{
|
||||
'name': 'Evaluation 1',
|
||||
'dtype': 'cashbooks',
|
||||
'cashbooks': [('add', [x.id for x in books])],
|
||||
}])
|
||||
self.assertEqual(len(evaluation.cashbooks), 3)
|
||||
self.assertEqual(len(evaluation.types), 0)
|
||||
self.assertEqual(len(evaluation.currencies), 0)
|
||||
|
||||
Evaluation.write(*[
|
||||
[evaluation],
|
||||
{
|
||||
'dtype': 'types',
|
||||
'types': [('add', [x.id for x in Types.search([])])],
|
||||
}])
|
||||
self.assertEqual(len(evaluation.cashbooks), 0)
|
||||
self.assertEqual(len(evaluation.types), 2)
|
||||
self.assertEqual(len(evaluation.currencies), 0)
|
||||
|
||||
# write same dtype again - no change
|
||||
Evaluation.write(*[
|
||||
[evaluation],
|
||||
{
|
||||
'dtype': 'types',
|
||||
}])
|
||||
self.assertEqual(len(evaluation.cashbooks), 0)
|
||||
self.assertEqual(len(evaluation.types), 2)
|
||||
self.assertEqual(len(evaluation.currencies), 0)
|
||||
|
||||
Evaluation.write(*[
|
||||
[evaluation],
|
||||
{
|
||||
'dtype': 'currencies',
|
||||
'currencies': [('add', [x.id for x in Currency.search([])])],
|
||||
}])
|
||||
self.assertEqual(len(evaluation.cashbooks), 0)
|
||||
self.assertEqual(len(evaluation.types), 0)
|
||||
self.assertEqual(len(evaluation.currencies), 2)
|
||||
|
||||
Evaluation.write(*[
|
||||
[evaluation],
|
||||
{
|
||||
'dtype': 'cashbooks',
|
||||
}])
|
||||
self.assertEqual(len(evaluation.cashbooks), 0)
|
||||
self.assertEqual(len(evaluation.types), 0)
|
||||
self.assertEqual(len(evaluation.currencies), 0)
|
||||
|
||||
@with_transaction()
|
||||
def test_report_dtype_validation(self):
|
||||
""" check validation of dtype
|
||||
"""
|
||||
pool = Pool()
|
||||
Evaluation = pool.get('cashbook_report.evaluation')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
books = self.prep_report_3books()
|
||||
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
# valid
|
||||
evaluation, = Evaluation.create([{
|
||||
'name': 'Evaluation 1',
|
||||
'dtype': 'cashbooks',
|
||||
'cashbooks': [('add', [x.id for x in books])],
|
||||
}])
|
||||
|
||||
# must fail
|
||||
self.assertRaisesRegex(UserError,
|
||||
"Type of evaluation must be 'Cashbooks'.",
|
||||
Evaluation.create,
|
||||
[{
|
||||
'name': 'Evaluation 1',
|
||||
'dtype': 'types', # wrong dtype
|
||||
'cashbooks': [('add', [x.id for x in books])],
|
||||
}])
|
||||
|
||||
@with_transaction()
|
||||
def test_report_chart_pie_book_red(self):
|
||||
""" create 3x cashbooks, add bookings,
|
||||
create report, check
|
||||
create report with cashbooks, check
|
||||
"""
|
||||
Evaluation = Pool().get('cashbook_report.evaluation')
|
||||
|
||||
|
@ -123,14 +223,76 @@ class ReportTestCase(CashbookTestCase):
|
|||
}):
|
||||
evaluation, = Evaluation.create([{
|
||||
'name': 'Evaluation 1',
|
||||
'lines': [('add', [x.id for x in books])],
|
||||
'cashbooks': [('add', [x.id for x in books])],
|
||||
}])
|
||||
self.assertEqual(len(evaluation.lines), 3)
|
||||
self.assertEqual(evaluation.dtype, 'book')
|
||||
self.assertEqual(evaluation.dtype, 'cashbooks')
|
||||
self.assertEqual(evaluation.chart, 'pie')
|
||||
self.assertEqual(evaluation.legend, True)
|
||||
self.assertEqual(evaluation.posted, False)
|
||||
self.assertEqual(evaluation.maincolor, 'default')
|
||||
self.assertEqual(evaluation.bgcolor, '#ffffc0')
|
||||
|
||||
self.assertEqual(len(evaluation.cashbooks), 3)
|
||||
self.assertEqual(evaluation.cashbooks[0].rec_name, 'Book 1 | 25.00 usd | Open')
|
||||
self.assertEqual(evaluation.cashbooks[1].rec_name, 'Book 2 | 12.50 usd | Open')
|
||||
self.assertEqual(evaluation.cashbooks[2].rec_name, 'Book 3 | 23.00 € | Open')
|
||||
|
||||
@with_transaction()
|
||||
def test_report_chart_pie_type_red(self):
|
||||
""" create 3x cashbooks, add bookings,
|
||||
create report with types of cashbooks, check
|
||||
"""
|
||||
pool = Pool()
|
||||
Evaluation = pool.get('cashbook_report.evaluation')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
books = self.prep_report_3books()
|
||||
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
evaluation, = Evaluation.create([{
|
||||
'name': 'Evaluation 1',
|
||||
'dtype': 'types',
|
||||
'types': [('add', [x.id for x in Types.search([])])],
|
||||
}])
|
||||
self.assertEqual(evaluation.dtype, 'types')
|
||||
self.assertEqual(evaluation.chart, 'pie')
|
||||
self.assertEqual(evaluation.legend, True)
|
||||
self.assertEqual(evaluation.posted, False)
|
||||
self.assertEqual(evaluation.maincolor, 'default')
|
||||
self.assertEqual(evaluation.bgcolor, '#ffffc0')
|
||||
|
||||
self.assertEqual(len(evaluation.types), 2)
|
||||
|
||||
@with_transaction()
|
||||
def test_report_chart_pie_currency_red(self):
|
||||
""" create 3x cashbooks, add bookings,
|
||||
create report with types of cashbooks, check
|
||||
"""
|
||||
pool = Pool()
|
||||
Evaluation = pool.get('cashbook_report.evaluation')
|
||||
Currency = pool.get('currency.currency')
|
||||
|
||||
books = self.prep_report_3books()
|
||||
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({
|
||||
'company': company.id,
|
||||
}):
|
||||
evaluation, = Evaluation.create([{
|
||||
'name': 'Evaluation 1',
|
||||
'dtype': 'currencies',
|
||||
'currencies': [('add', [x.id for x in Currency.search([])])],
|
||||
}])
|
||||
self.assertEqual(evaluation.dtype, 'currencies')
|
||||
self.assertEqual(evaluation.chart, 'pie')
|
||||
self.assertEqual(evaluation.legend, True)
|
||||
self.assertEqual(evaluation.posted, False)
|
||||
self.assertEqual(evaluation.maincolor, 'default')
|
||||
self.assertEqual(evaluation.bgcolor, '#ffffc0')
|
||||
|
||||
self.assertEqual(len(evaluation.currencies), 2)
|
||||
|
||||
# end ReportTestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue