line: reiter für monate, kategorie + test
This commit is contained in:
parent
d6a8b254a3
commit
a23407f515
9 changed files with 333 additions and 3 deletions
|
@ -8,6 +8,7 @@ from trytond.pool import Pool
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from datetime import date
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
class LineTestCase(ModuleTestCase):
|
||||
|
@ -24,6 +25,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
category = self.prep_category()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
|
@ -31,9 +33,11 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -55,6 +59,106 @@ class LineTestCase(ModuleTestCase):
|
|||
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'open')]), 2)
|
||||
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'closed')]), 0)
|
||||
|
||||
@with_transaction()
|
||||
def test_line_create_check_deny_write(self):
|
||||
""" create cashbook + line, 'close' book, write to line
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Line = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
category = self.prep_category()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
self.assertEqual(book.state, 'open')
|
||||
self.assertEqual(len(book.lines), 2)
|
||||
|
||||
Book.wfclosed([book])
|
||||
self.assertEqual(book.state, 'closed')
|
||||
|
||||
self.assertRaisesRegex(UserError,
|
||||
"The cash book 'Book 1' is 'Closed' and cannot be changed.",
|
||||
Line.write,
|
||||
*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'description': 'should be denied',
|
||||
},
|
||||
])
|
||||
|
||||
@with_transaction()
|
||||
def test_line_create_check_month(self):
|
||||
""" create cashbook + line, check 'month' + search
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Types = pool.get('cashbook.type')
|
||||
Line = pool.get('cashbook.line')
|
||||
IrDate = pool.get('ir.date')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
category = self.prep_category()
|
||||
|
||||
IrDate.today = MagicMock(return_value=date(2022, 6, 1))
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'date': date(2022, 6, 1),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
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].month, 1)
|
||||
self.assertEqual(book.lines[1].date, date(2022, 6, 1))
|
||||
self.assertEqual(book.lines[1].month, 0)
|
||||
|
||||
l1, = Line.search([('month', '=', 0)])
|
||||
self.assertEqual(l1.date, date(2022, 6, 1))
|
||||
l1, = Line.search([('month', '=', 1)])
|
||||
self.assertEqual(l1.date, date(2022, 5, 1))
|
||||
|
||||
IrDate.today = MagicMock(return_value=date(2022, 6, 30))
|
||||
|
||||
l1, = Line.search([('month', '=', 0)])
|
||||
self.assertEqual(l1.date, date(2022, 6, 1))
|
||||
l1, = Line.search([('month', '=', 1)])
|
||||
self.assertEqual(l1.date, date(2022, 5, 1))
|
||||
|
||||
self.assertEqual(Line.search_count([('month', '=', 2)]), 0)
|
||||
|
||||
IrDate.today = MagicMock(return_value=date(2022, 7, 1))
|
||||
|
||||
self.assertEqual(Line.search_count([('month', '=', 0)]), 0)
|
||||
l1, = Line.search([('month', '=', 1)])
|
||||
self.assertEqual(l1.date, date(2022, 6, 1))
|
||||
|
||||
IrDate.today = MagicMock(return_value=date.today())
|
||||
|
||||
@with_transaction()
|
||||
def test_line_delete_with_book_in_open_state(self):
|
||||
""" create cashbook + line, book in state=open, delete a line
|
||||
|
@ -65,6 +169,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
category = self.prep_category()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
|
@ -72,9 +177,11 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -93,6 +200,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
category = self.prep_category()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
|
@ -100,9 +208,11 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -126,6 +236,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types, = Types.search([('short', '=','CAS')])
|
||||
category = self.prep_category()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
|
@ -133,9 +244,11 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category.id,
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'description': 'Text 2',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.name, 'Book 1')
|
||||
|
@ -163,6 +276,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
category = self.prep_category()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
usr_lst = ResUser.create([{
|
||||
'login': 'frida',
|
||||
|
@ -184,6 +298,7 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Test 1',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
@ -223,6 +338,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
category = self.prep_category()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
grp_reviewer, = ResGroup.create([{
|
||||
'name': 'Cashbook Reviewer',
|
||||
|
@ -251,6 +367,7 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Test 1',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
@ -297,6 +414,7 @@ class LineTestCase(ModuleTestCase):
|
|||
Types = pool.get('cashbook.type')
|
||||
|
||||
types, = Types.search([('short', '=', 'CAS')])
|
||||
category = self.prep_category()
|
||||
grp_cashbook, = ResGroup.search([('name', '=', 'Cashbook')])
|
||||
grp_observer, = ResGroup.create([{
|
||||
'name': 'Cashbook Observer',
|
||||
|
@ -325,6 +443,7 @@ class LineTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Test 1',
|
||||
'category': category.id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(book.rec_name, 'Fridas book'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue