line, book - wf + tests
This commit is contained in:
parent
ba442b726e
commit
654e9d2ee7
25 changed files with 786 additions and 160 deletions
|
@ -4,14 +4,17 @@
|
|||
import trytond.tests.test_tryton
|
||||
import unittest
|
||||
|
||||
from trytond.modules.cashbook.tests.test_accounttype import AccounttypeTestCase
|
||||
|
||||
from trytond.modules.cashbook.tests.test_type import TypeTestCase
|
||||
from trytond.modules.cashbook.tests.test_book import BookTestCase
|
||||
from trytond.modules.cashbook.tests.test_line import LineTestCase
|
||||
|
||||
__all__ = ['suite']
|
||||
|
||||
|
||||
class CashbookTestCase(\
|
||||
AccounttypeTestCase,
|
||||
LineTestCase,
|
||||
BookTestCase,
|
||||
TypeTestCase,
|
||||
):
|
||||
'Test cashbook module'
|
||||
module = 'cashbook'
|
||||
|
|
176
tests/test_book.py
Normal file
176
tests/test_book.py
Normal file
|
@ -0,0 +1,176 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import os, requests
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from datetime import date
|
||||
|
||||
|
||||
class BookTestCase(ModuleTestCase):
|
||||
'Test cashbook book module'
|
||||
module = 'cashbook'
|
||||
|
||||
@with_transaction()
|
||||
def test_book_create(self):
|
||||
""" create cashbook
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.btype.rec_name, 'CAS - Cash')
|
||||
self.assertEqual(book.state, 'open')
|
||||
self.assertEqual(book.state_string, 'Open')
|
||||
|
||||
@with_transaction()
|
||||
def test_book_deny_delete_open(self):
|
||||
""" create cashbook, add lines, try to delete in state 'open'
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'test 1',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
|
||||
Book.delete,
|
||||
[book])
|
||||
|
||||
@with_transaction()
|
||||
def test_book_deny_delete_closed(self):
|
||||
""" create cashbook, add lines, try to delete in state 'closed'
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'test 1',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
Book.wfclosed([book])
|
||||
self.assertEqual(book.state, 'closed')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
|
||||
Book.delete,
|
||||
[book])
|
||||
|
||||
@with_transaction()
|
||||
def test_book_deny_delete_archive(self):
|
||||
""" create cashbook, add lines, try to delete in state 'archive'
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'test 1',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
Book.wfclosed([book])
|
||||
Book.wfarchive([book])
|
||||
self.assertEqual(book.state, 'archive')
|
||||
|
||||
Book.delete([book])
|
||||
|
||||
@with_transaction()
|
||||
def test_book_deny_update_1(self):
|
||||
""" create cashbook, try to update in states open, closed, archive
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
|
||||
Book.write(*[
|
||||
[book],
|
||||
{
|
||||
'name': 'Book 1a',
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1a')
|
||||
|
||||
# wf: open --> closed
|
||||
Book.wfclosed([book])
|
||||
self.assertEqual(book.state, 'closed')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1a' is 'Closed' and cannot be changed.",
|
||||
Book.write,
|
||||
*[
|
||||
[book],
|
||||
{
|
||||
'name': 'Book 1b',
|
||||
},
|
||||
])
|
||||
|
||||
Book.wfopen([book])
|
||||
self.assertEqual(book.state, 'open')
|
||||
|
||||
Book.write(*[
|
||||
[book],
|
||||
{
|
||||
'name': 'Book 1c',
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1c')
|
||||
|
||||
Book.wfclosed([book])
|
||||
Book.wfarchive([book])
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1c' is 'Archive' and cannot be changed.",
|
||||
Book.write,
|
||||
*[
|
||||
[book],
|
||||
{
|
||||
'name': 'Book 1d',
|
||||
},
|
||||
])
|
||||
|
||||
# end BookTestCase
|
153
tests/test_line.py
Normal file
153
tests/test_line.py
Normal file
|
@ -0,0 +1,153 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import os, requests
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from datetime import date
|
||||
|
||||
|
||||
class LineTestCase(ModuleTestCase):
|
||||
'Test cashbook line module'
|
||||
module = 'cashbook'
|
||||
|
||||
@with_transaction()
|
||||
def test_line_create_check_names_search(self):
|
||||
""" create cashbook + line
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.btype.rec_name, 'CAS - Cash')
|
||||
self.assertEqual(book.state, 'open')
|
||||
self.assertEqual(len(book.lines), 2)
|
||||
self.assertEqual(book.lines[0].date, date(2022, 5, 1))
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022 Text 1')
|
||||
self.assertEqual(book.lines[0].state_cashbook, 'open')
|
||||
self.assertEqual(book.lines[1].date, date(2022, 5, 2))
|
||||
self.assertEqual(book.lines[1].rec_name, '05/02/2022 Text 2')
|
||||
|
||||
self.assertEqual(Lines.search_count([('rec_name', '=', 'Text 1')]), 1)
|
||||
self.assertEqual(Lines.search_count([('rec_name', '=', 'Text 1a')]), 0)
|
||||
self.assertEqual(Lines.search_count([('rec_name', 'ilike', 'text%')]), 2)
|
||||
|
||||
self.assertEqual(Lines.search_count([('state_cashbook', '=', 'open')]), 2)
|
||||
self.assertEqual(Lines.search_count([('state_cashbook', '=', 'closed')]), 0)
|
||||
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'open')]), 2)
|
||||
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'closed')]), 0)
|
||||
|
||||
@with_transaction()
|
||||
def test_line_delete_with_book_in_open_state(self):
|
||||
""" create cashbook + line, book in state=open, delete a line
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(len(book.lines), 2)
|
||||
self.assertEqual(book.state, 'open')
|
||||
|
||||
Lines.delete([book.lines[0]])
|
||||
|
||||
@with_transaction()
|
||||
def test_line_delete_with_book_in_closed_state(self):
|
||||
""" create cashbook + line, book in state=closed, delete a line
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(len(book.lines), 2)
|
||||
self.assertEqual(book.state, 'open')
|
||||
Book.wfclosed([book])
|
||||
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'.",
|
||||
Lines.delete,
|
||||
[book.lines[0]])
|
||||
|
||||
@with_transaction()
|
||||
def test_line_delete_with_line_in_check_state(self):
|
||||
""" create cashbook + line, line in state=check, delete a line
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(len(book.lines), 2)
|
||||
self.assertEqual(book.state, 'open')
|
||||
|
||||
self.assertEqual(book.lines[0].state, 'edit')
|
||||
Lines.wfcheck([book.lines[0]])
|
||||
self.assertEqual(book.lines[0].state, 'check')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cashbook line '05/01/2022 Text 1' cannot be deleted, its in state 'Checked'.",
|
||||
Lines.delete,
|
||||
[book.lines[0]])
|
||||
|
||||
# end BookTestCase
|
|
@ -8,12 +8,24 @@ from trytond.transaction import Transaction
|
|||
from trytond.exceptions import UserError
|
||||
|
||||
|
||||
class AccounttypeTestCase(ModuleTestCase):
|
||||
'Test account type module'
|
||||
class TypeTestCase(ModuleTestCase):
|
||||
'Test cashbook type module'
|
||||
module = 'cashbook'
|
||||
|
||||
@with_transaction()
|
||||
def test_accounttype_create(self):
|
||||
def test_type_read_existing(self):
|
||||
""" read predefined types
|
||||
"""
|
||||
AccType = Pool().get('cashbook.type')
|
||||
|
||||
t_lst = AccType.search([], order=[('name', 'ASC')])
|
||||
self.assertEqual(len(t_lst), 3)
|
||||
self.assertEqual(t_lst[0].rec_name, 'CAS - Cash')
|
||||
self.assertEqual(t_lst[1].rec_name, 'FTD - Fixed-term deposit')
|
||||
self.assertEqual(t_lst[2].rec_name, 'GIR - Giro')
|
||||
|
||||
@with_transaction()
|
||||
def test_type_create(self):
|
||||
""" create account type
|
||||
"""
|
||||
AccType = Pool().get('cashbook.type')
|
||||
|
@ -34,4 +46,4 @@ class AccounttypeTestCase(ModuleTestCase):
|
|||
'short': 'T1',
|
||||
}])
|
||||
|
||||
# end AccounttypeTestCase
|
||||
# end TypeTestCase
|
Loading…
Add table
Add a link
Reference in a new issue