book: start-saldo + sperre bei lines>0, saldo, rec_name + tests

This commit is contained in:
Frederik Jaeckel 2022-08-11 13:01:53 +02:00
parent 8fd6e0d339
commit ae5303658e
9 changed files with 218 additions and 40 deletions

View file

@ -62,7 +62,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.state, 'open')
self.assertRaisesRegex(UserError,
"The cashbook 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
"The cashbook 'Book 1 | 1.00 usd | Open' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
Book.delete,
[book])
@ -95,7 +95,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cashbook 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
"The cashbook 'Book 1 | 1.00 usd | Closed' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
Book.delete,
[book])
@ -160,7 +160,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cash book 'Book 1a' is 'Closed' and cannot be changed.",
"The cash book 'Book 1a | 1.00 usd | Closed' is 'Closed' and cannot be changed.",
Book.write,
*[
[book],
@ -183,7 +183,7 @@ class BookTestCase(ModuleTestCase):
Book.wfarchive([book])
self.assertRaisesRegex(UserError,
"The cash book 'Book 1c' is 'Archive' and cannot be changed.",
"The cash book 'Book 1c | 0.00 usd | Archive' is 'Archive' and cannot be changed.",
Book.write,
*[
[book],
@ -192,6 +192,59 @@ class BookTestCase(ModuleTestCase):
},
])
@with_transaction()
def test_book_deny_update_start_amount(self):
""" create cashbook, add lines, update start-amount
"""
pool = Pool()
Book = pool.get('cashbook.book')
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,
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.start_balance, Decimal('0.0'))
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
Book.write(*[
[book],
{
'start_balance': Decimal('1.0'),
}])
self.assertEqual(book.start_balance, Decimal('1.0'))
self.assertEqual(book.balance, Decimal('1.0'))
Book.write(*[
[book],
{
'lines': [('create', [{
'amount': Decimal('2.0'),
'description': 'Test',
'category': category.id,
'bookingtype': 'in',
}])],
}])
self.assertEqual(book.start_balance, Decimal('1.0'))
self.assertEqual(book.balance, Decimal('3.0'))
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].balance, Decimal('3.0'))
self.assertRaisesRegex(UserError,
"The initial amount of the cash book 'Fridas book | 3.00 usd | Open' cannot be changed because it already contains bookings.",
Book.write,
*[
[book],
{
'start_balance': Decimal('1.5'),
},
])
@with_transaction()
def test_book_permission_owner(self):
""" create book + 2x users, add users to group, check access
@ -228,7 +281,7 @@ class BookTestCase(ModuleTestCase):
'company': company.id,
'currency': company.currency.id,
}])
self.assertEqual(book.rec_name, 'Fridas book'),
self.assertEqual(book.rec_name, 'Fridas book | 0.00 usd | Open'),
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
@ -243,7 +296,7 @@ class BookTestCase(ModuleTestCase):
with Transaction().set_user(usr_lst[0].id):
books = Book.search([])
self.assertEqual(len(books), 1)
self.assertEqual(books[0].rec_name, 'Fridas book')
self.assertEqual(books[0].rec_name, 'Fridas book | 0.00 usd | Open')
self.assertRaisesRegex(UserError,
'You are not allowed to access "Cashbook".',
@ -298,7 +351,7 @@ class BookTestCase(ModuleTestCase):
'currency': company.currency.id,
'btype': types.id,
}])
self.assertEqual(book.rec_name, 'Fridas book'),
self.assertEqual(book.rec_name, 'Fridas book | 0.00 usd | Open'),
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
@ -315,7 +368,7 @@ class BookTestCase(ModuleTestCase):
with Transaction().set_user(usr_lst[0].id):
books = Book.search([])
self.assertEqual(len(books), 1)
self.assertEqual(books[0].rec_name, 'Fridas book')
self.assertEqual(books[0].rec_name, 'Fridas book | 0.00 usd | Open')
@with_transaction()
def test_book_permission_observer(self):
@ -360,7 +413,7 @@ class BookTestCase(ModuleTestCase):
'currency': company.currency.id,
'btype': types.id,
}])
self.assertEqual(book.rec_name, 'Fridas book'),
self.assertEqual(book.rec_name, 'Fridas book | 0.00 usd | Open'),
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
@ -377,6 +430,6 @@ class BookTestCase(ModuleTestCase):
with Transaction().set_user(usr_lst[0].id):
books = Book.search([])
self.assertEqual(len(books), 1)
self.assertEqual(books[0].rec_name, 'Fridas book')
self.assertEqual(books[0].rec_name, 'Fridas book | 0.00 usd | Open')
# end BookTestCase

View file

@ -131,7 +131,7 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cash book 'Book 1' is 'Closed' and cannot be changed.",
"The cash book 'Book | 2.00 usd | Closed' is 'Closed' and cannot be changed.",
Line.write,
*[
[book.lines[0]],
@ -478,7 +478,7 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cashbook line '05/01/2022 Text 1' cannot be deleted because the Cashbook 'Book 1' is in state 'Closed'.",
"The cashbook line '05/01/2022 Text 1' cannot be deleted because the Cashbook 'Book | 2.00 usd | Closed' is in state 'Closed'.",
Lines.delete,
[book.lines[0]])
@ -570,7 +570,7 @@ class LineTestCase(ModuleTestCase):
'amount': Decimal('1.0'),
}])],
}])
self.assertEqual(book.rec_name, 'Fridas book'),
self.assertEqual(book.rec_name, 'Fridas book | 1.00 usd | Open'),
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
@ -585,7 +585,7 @@ class LineTestCase(ModuleTestCase):
with Transaction().set_user(usr_lst[0].id):
lines = Line.search([])
self.assertEqual(len(lines), 1)
self.assertEqual(lines[0].cashbook.rec_name, 'Fridas book')
self.assertEqual(lines[0].cashbook.rec_name, 'Fridas book | 1.00 usd | Open')
self.assertEqual(lines[0].rec_name, '05/01/2022 Test 1')
Line.write(*[
@ -647,7 +647,7 @@ class LineTestCase(ModuleTestCase):
'amount': Decimal('1.0'),
}])],
}])
self.assertEqual(book.rec_name, 'Fridas book'),
self.assertEqual(book.rec_name, 'Fridas book | 1.00 usd | Open'),
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
@ -731,7 +731,7 @@ class LineTestCase(ModuleTestCase):
'amount': Decimal('1.0'),
}])],
}])
self.assertEqual(book.rec_name, 'Fridas book'),
self.assertEqual(book.rec_name, 'Fridas book | 1.00 usd | Open'),
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({