prepare test for porting

This commit is contained in:
Frederik Jaeckel 2023-06-02 20:40:12 +02:00
parent 619a17bcd6
commit 3467c08895
16 changed files with 690 additions and 373 deletions

View file

@ -287,7 +287,9 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
if self.btype:
return '%(name)s | %(balance)s %(symbol)s | %(state)s' % {
'name': recname or '-',
'balance': Report.format_number(self.balance or 0.0, None),
'balance': Report.format_number(
self.balance or 0.0, None,
digits=getattr(self.currency, 'digits', 2)),
'symbol': getattr(self.currency, 'symbol', '-'),
'state': self.state_string,
}

View file

@ -174,7 +174,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
reconciliation = fields.Many2One(
string='Reconciliation', readonly=True,
model_name='cashbook.recon', ondelete='SET NULL',
domain=[('cashbook.id', '=', Eval('cashbook'))],
domain=[('cashbook.id', '=', Eval('cashbook', -1))],
depends=['cashbook'],
states={
'invisible': ~Bool(Eval('reconciliation')),
@ -487,7 +487,9 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
return '%(date)s|%(type)s|%(amount)s %(symbol)s|%(desc)s [%(category)s]' % {
'date': Report.format_date(self.date),
'desc': (self.description or '-')[:40],
'amount': Report.format_number(credit - debit, None),
'amount': Report.format_number(
credit - debit, None,
digits=getattr(self.currency, 'digits', 2)),
'symbol': getattr(self.currency, 'symbol', '-'),
'category': self.category_view
if self.bookingtype in ['in', 'out']

View file

@ -23,6 +23,8 @@ DEPENDS = ['state', 'state_cashbook']
class SecondCurrencyMixin:
""" two fields for 2nd currency: amount + rate
"""
__slots__ = ()
amount_2nd_currency = fields.Numeric(
string='Amount Second Currency',
digits=(16, Eval('currency2nd_digits', 2)),
@ -202,6 +204,8 @@ class SecondCurrencyMixin:
class MemCacheIndexMx:
""" add index to 'create_date' + 'write_date'
"""
__slots__ = ()
@classmethod
def __setup__(cls):
super(MemCacheIndexMx, cls).__setup__()

View file

@ -81,8 +81,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
('date', '<=', Eval('date_to')),
],
domain=[
('date', '>=', Eval('date_from')),
('date', '<=', Eval('date_to')),
('date', '>=', Eval('date_from', None)),
('date', '<=', Eval('date_to', None)),
])
currency = fields.Function(fields.Many2One(
@ -327,8 +327,11 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
'to': Report.format_date(self.date_to, None)
if self.date_to is not None else '-',
'start_amount': Report.format_number(
self.start_amount or 0.0, None),
'end_amount': Report.format_number(self.end_amount or 0.0, None),
self.start_amount or 0.0, None,
digits=getattr(self.currency, 'digits', 2)),
'end_amount': Report.format_number(
self.end_amount or 0.0, None,
digits=getattr(self.currency, 'digits', 2)),
'symbol': getattr(self.currency, 'symbol', '-'),
'num': len(self.lines),
}

View file

@ -121,7 +121,9 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
"""
return '%(type)s|%(amount)s %(symbol)s|%(desc)s [%(target)s]' % {
'desc': (self.description or '-')[:40],
'amount': Report.format_number(self.amount, None),
'amount': Report.format_number(
self.amount, None,
digits=getattr(self.currency, 'digits', 2)),
'symbol': getattr(self.currency, 'symbol', '-'),
'target': self.category_view
if self.splittype == 'cat' else self.booktransf.rec_name,

View file

@ -4,36 +4,12 @@
import trytond.tests.test_tryton
import unittest
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
from trytond.modules.cashbook.tests.test_splitline import SplitLineTestCase
from trytond.modules.cashbook.tests.test_config import ConfigTestCase
from trytond.modules.cashbook.tests.test_category import CategoryTestCase
from trytond.modules.cashbook.tests.test_reconciliation import ReconTestCase
from trytond.modules.cashbook.tests.test_bookingwiz import BookingWizardTestCase
from trytond.modules.cashbook.tests.test_currency import CurrencyTestCase
from .test_module import CashbookTestCase
__all__ = ['suite']
class CashbookTestCase(\
CurrencyTestCase, \
BookingWizardTestCase,\
ReconTestCase,\
CategoryTestCase,\
ConfigTestCase,\
LineTestCase,
SplitLineTestCase,
BookTestCase,
TypeTestCase,
):
'Test cashbook module'
module = 'cashbook'
# end CashbookTestCase
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookTestCase))

View file

@ -90,8 +90,7 @@ class BookTestCase(ModuleTestCase):
}])
with Transaction().set_context({
'date': date(2022, 5, 5),
}):
'date': date(2022, 5, 5)}):
self.assertEqual(book.rec_name, 'Book 1 | 10.00 usd | Open')
self.assertEqual(book.currency.rec_name, 'usd')
self.assertEqual(book.currency.rate, Decimal('1.05'))
@ -102,7 +101,8 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.balance_ref, Decimal('9.52'))
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name,
self.assertEqual(
book.lines[0].rec_name,
'05/05/2022|Rev|10.00 usd|Amount in USD [Cat1]')
@with_transaction()
@ -145,8 +145,7 @@ class BookTestCase(ModuleTestCase):
}])
with Transaction().set_context({
'date': date(2022, 5, 5),
}):
'date': date(2022, 5, 5)}):
self.assertEqual(book.rec_name, 'Book 1')
self.assertEqual(book.currency.rec_name, 'Euro')
self.assertEqual(book.currency.rate, Decimal('1.0'))
@ -156,7 +155,9 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(len(book.lines), 0)
self.assertEqual(len(book.childs), 1)
self.assertEqual(book.childs[0].rec_name, 'Book 1/Book 2 | 10.00 usd | Open')
self.assertEqual(
book.childs[0].rec_name,
'Book 1/Book 2 | 10.00 usd | Open')
self.assertEqual(book.childs[0].currency.rec_name, 'usd')
self.assertEqual(book.childs[0].currency.rate, Decimal('1.05'))
self.assertEqual(book.childs[0].company_currency.rec_name, 'Euro')
@ -188,7 +189,9 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.name, 'Level 1')
self.assertEqual(book.rec_name, 'Level 1')
self.assertEqual(len(book.childs), 1)
self.assertEqual(book.childs[0].rec_name, 'Level 1/Level 2 | 0.00 usd | Open')
self.assertEqual(
book.childs[0].rec_name,
'Level 1/Level 2 | 0.00 usd | Open')
@with_transaction()
def test_book_deny_delete_open(self):
@ -220,8 +223,10 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.state, 'open')
self.assertRaisesRegex(UserError,
"The cashbook 'Book 1 | 1.00 usd | Open' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
self.assertRaisesRegex(
UserError,
"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])
@ -336,8 +341,10 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.btype.feature, 'gen')
self.assertEqual(book.feature, 'gen')
self.assertRaisesRegex(UserError,
"The type cannot be deleted on the cash book 'Book 1 | 1.00 usd | Open' because it still contains 1 lines.",
self.assertRaisesRegex(
UserError,
"The type cannot be deleted on the cash book 'Book 1 | " +
"1.00 usd | Open' because it still contains 1 lines.",
Book.write,
*[
[book],
@ -393,8 +400,11 @@ class BookTestCase(ModuleTestCase):
Book.wfclosed([book])
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cashbook 'Book 1 | 1.00 usd | Closed' cannot be deleted because it contains 1 lines and is not in the status 'Archive'.",
self.assertRaisesRegex(
UserError,
"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])
@ -463,8 +473,10 @@ class BookTestCase(ModuleTestCase):
Book.wfclosed([book])
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cash book 'Book 1a | 1.00 usd | Closed' is 'Closed' and cannot be changed.",
self.assertRaisesRegex(
UserError,
"The cash book 'Book 1a | 1.00 usd | Closed' is 'Closed' " +
"and cannot be changed.",
Book.write,
*[
[book],
@ -486,8 +498,10 @@ class BookTestCase(ModuleTestCase):
Book.wfclosed([book])
Book.wfarchive([book])
self.assertRaisesRegex(UserError,
"The cash book 'Book 1c | 0.00 usd | Archive' is 'Archive' and cannot be changed.",
self.assertRaisesRegex(
UserError,
"The cash book 'Book 1c | 0.00 usd | Archive' is 'Archive'" +
" and cannot be changed.",
Book.write,
*[
[book],
@ -537,8 +551,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'diego' , try access
with Transaction().set_user(usr_lst[1].id):
books = Book.search([])
@ -548,9 +561,12 @@ 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 | 0.00 usd | Open')
self.assertEqual(
books[0].rec_name,
'Fridas book | 0.00 usd | Open')
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'You are not allowed to access "Cashbook.Name".',
Book.write,
*[
@ -562,7 +578,8 @@ class BookTestCase(ModuleTestCase):
@with_transaction()
def test_book_permission_reviewer(self):
""" create book + 2x users + 1x reviewer-group, add users to group, check access
""" create book + 2x users + 1x reviewer-group,
add users to group, check access
"""
pool = Pool()
ResUser = pool.get('res.user')
@ -608,8 +625,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'diego' , try access
with Transaction().set_user(usr_lst[1].id):
books = Book.search([])
@ -621,11 +637,14 @@ 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 | 0.00 usd | Open')
self.assertEqual(
books[0].rec_name,
'Fridas book | 0.00 usd | Open')
@with_transaction()
def test_book_permission_observer(self):
""" create book + 2x users + 1x observer-group, add users to group, check access
""" create book + 2x users + 1x observer-group,
add users to group, check access
"""
pool = Pool()
ResUser = pool.get('res.user')
@ -671,8 +690,7 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'diego' , try access
with Transaction().set_user(usr_lst[1].id):
books = Book.search([])
@ -684,6 +702,8 @@ 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 | 0.00 usd | Open')
self.assertEqual(
books[0].rec_name,
'Fridas book | 0.00 usd | Open')
# end BookTestCase

View file

@ -6,7 +6,6 @@
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
from decimal import Decimal
from unittest.mock import MagicMock
@ -29,8 +28,7 @@ class BookingWizardTestCase(ModuleTestCase):
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
}):
'company': company.id}):
types = self.prep_type()
book, = Book.create([{
'name': 'Cash Book',
@ -43,11 +41,11 @@ class BookingWizardTestCase(ModuleTestCase):
party, = Party.create([{
'name': 'Foodshop Zehlendorf',
'addresses':[('create', [{}])],
'addresses': [('create', [{}])],
}])
categories = Category.create([{
'name':'Income',
'name': 'Income',
'cattype': 'in',
}, {
'name': 'Food',
@ -88,7 +86,9 @@ class BookingWizardTestCase(ModuleTestCase):
IrDate.today = MagicMock(return_value=date.today())
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Exp|-10.00 usd|Test 1 [Food]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Exp|-10.00 usd|Test 1 [Food]')
@with_transaction()
def test_bookwiz_transfer(self):
@ -103,8 +103,7 @@ class BookingWizardTestCase(ModuleTestCase):
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
}):
'company': company.id}):
types = self.prep_type()
books = Book.create([{
'name': 'Cash Book',
@ -124,11 +123,11 @@ class BookingWizardTestCase(ModuleTestCase):
party, = Party.create([{
'name': 'Foodshop Zehlendorf',
'addresses':[('create', [{}])],
'addresses': [('create', [{}])],
}])
categories = Category.create([{
'name':'Income',
Category.create([{
'name': 'Income',
'cattype': 'in',
}, {
'name': 'Food',
@ -170,7 +169,8 @@ class BookingWizardTestCase(ModuleTestCase):
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(len(books[1].lines), 0)
self.assertEqual(books[0].lines[0].rec_name,
self.assertEqual(
books[0].lines[0].rec_name,
'05/01/2022|to|-10.00 usd|Test 1 [Bank | 0.00 usd | Open]')
# end BookingWizardTestCase

View file

@ -17,7 +17,6 @@ class CategoryTestCase(ModuleTestCase):
""" create category
"""
pool = Pool()
Company = pool.get('company.company')
Category = pool.get('cashbook.category')
company = self.prep_company()
@ -119,8 +118,10 @@ class CategoryTestCase(ModuleTestCase):
self.assertEqual(category.childs[0].rec_name, 'Level 1/Level 2')
self.assertEqual(category.childs[0].cattype, 'in')
self.assertRaisesRegex(UserError,
'The value for field "Type" in "Category" is not valid according to its domain.',
self.assertRaisesRegex(
UserError,
'The value for field "Type" in "Category" is not valid ' +
'according to its domain.',
Category.write,
*[
[category.childs[0]],
@ -140,7 +141,6 @@ class CategoryTestCase(ModuleTestCase):
self.assertEqual(category.childs[0].rec_name, 'Level 1/Level 2')
self.assertEqual(category.childs[0].cattype, 'out')
@with_transaction()
def test_category_create_nodupl_at_root(self):
""" create category, duplicates are allowed at root-level
@ -151,8 +151,7 @@ class CategoryTestCase(ModuleTestCase):
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
}):
'company': company.id}):
cat1, = Category.create([{
'name': 'Test 1',
'description': 'Info',
@ -177,7 +176,8 @@ class CategoryTestCase(ModuleTestCase):
self.assertEqual(cat2.parent, None)
# deny duplicate of same type
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'The category name already exists at this level.',
Category.create,
[{
@ -196,8 +196,7 @@ class CategoryTestCase(ModuleTestCase):
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
}):
'company': company.id}):
cat1, = Category.create([{
'name': 'Test 1',
'description': 'Info',
@ -223,9 +222,9 @@ class CategoryTestCase(ModuleTestCase):
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
}):
self.assertRaisesRegex(UserError,
'company': company.id}):
self.assertRaisesRegex(
UserError,
'The category name already exists at this level.',
Category.create,
[{

View file

@ -6,7 +6,6 @@
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 trytond.modules.company.tests import create_company
from datetime import date
from decimal import Decimal
@ -24,7 +23,7 @@ class ConfigTestCase(ModuleTestCase):
company = Company.search([])
if len(company) > 0:
company = company[0]
else :
else:
company = create_company(name='m-ds')
return company
@ -74,7 +73,7 @@ class ConfigTestCase(ModuleTestCase):
'rounding': Decimal('0.01'),
'digits': 2,
}])
else :
else:
euro = euros[0]
# set company-currency to euro
@ -169,8 +168,7 @@ class ConfigTestCase(ModuleTestCase):
self.assertEqual(usr_lst[1].name, 'Diego')
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'frida'
with Transaction().set_user(usr_lst[0].id):
cfg1 = Configuration()

View file

@ -5,7 +5,6 @@
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.modules.cashbook.model import CACHEKEY_CURRENCY, ENABLE_CACHE
from datetime import date
from decimal import Decimal
@ -53,18 +52,17 @@ class CurrencyTestCase(ModuleTestCase):
value = '%d-c%s' % (
currency.rates[0].id,
str(currency.rates[0].create_date.timestamp()))
if ENABLE_CACHE == True:
if ENABLE_CACHE is True:
self.assertEqual(MemCache.read_value(cache_key), value)
else :
else:
self.assertEqual(MemCache.read_value(cache_key), None)
time.sleep(1.0)
Currency.write(*[
[currency],
{
'rates': [('write',
[currency.rates[0].id],
{
'rates': [
('write', [currency.rates[0].id], {
'rate': Decimal('1.06'),
})],
}])
@ -73,9 +71,9 @@ class CurrencyTestCase(ModuleTestCase):
value = '%d-w%s' % (
currency.rates[0].id,
str(currency.rates[0].write_date.timestamp()))
if ENABLE_CACHE == True:
if ENABLE_CACHE is True:
self.assertEqual(MemCache.read_value(cache_key), value)
else :
else:
self.assertEqual(MemCache.read_value(cache_key), None)
Currency.write(*[

View file

@ -3,7 +3,7 @@
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.tests.test_tryton import with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.exceptions import UserError
@ -12,10 +12,9 @@ from unittest.mock import MagicMock
from decimal import Decimal
class LineTestCase(ModuleTestCase):
'Test cashbook line module'
module = 'cashbook'
class LineTestCase(object):
""" test lines
"""
@with_transaction()
def test_line_check_add_amount2nd_currency(self):
""" create cashbook, lines, add transfer without
@ -76,15 +75,17 @@ class LineTestCase(ModuleTestCase):
}])],
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR ' +
'[Book EURO | 0.00 € | Open]')
self.assertEqual(books[0].lines[0].amount, Decimal('10.0'))
# auto-created
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('9.52'))
self.assertEqual(books[0].lines[0].rate_2nd_currency, Decimal('0.952'))
Lines.delete(books[0].lines)
# rate @ 2022-06-01: 1.02
# rate @ 2022-06-01: 1.02
Book.write(*[
[books[0]],
{
@ -97,8 +98,10 @@ class LineTestCase(ModuleTestCase):
}])],
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name,
'06/01/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'06/01/2022|to|-10.00 usd|Transfer USD --> EUR ' +
'[Book EURO | 0.00 € | Open]')
self.assertEqual(books[0].lines[0].amount, Decimal('10.0'))
# auto-created
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('9.80'))
@ -118,8 +121,10 @@ class LineTestCase(ModuleTestCase):
}])],
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> ' +
'EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(books[0].lines[0].amount, Decimal('10.0'))
# manual set
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('8.5'))
@ -205,15 +210,17 @@ class LineTestCase(ModuleTestCase):
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(len(books[1].lines), 0)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> ' +
'EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('9.52'))
# clear field 'amount_2nd_currency' to prepare for migration
clear_field = tab_line.update(
columns = [tab_line.amount_2nd_currency],
values = [None],
where = (tab_line.id == books[0].lines[0].id),
columns=[tab_line.amount_2nd_currency],
values=[None],
where=(tab_line.id == books[0].lines[0].id),
)
cursor.execute(*clear_field)
@ -229,7 +236,6 @@ class LineTestCase(ModuleTestCase):
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()
@ -269,8 +275,10 @@ class LineTestCase(ModuleTestCase):
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(len(books[1].lines), 0)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> ' +
'EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('9.52'))
self.assertEqual(books[0].lines[0].reference, None)
self.assertEqual(len(books[0].lines[0].references), 0)
@ -283,10 +291,14 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(books[0].lines[0].reference, None)
self.assertEqual(len(books[0].lines[0].references), 1)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 9.52 € | Open]')
self.assertEqual(books[1].lines[0].rec_name,
'05/05/2022|from|9.52 €|Transfer USD --> EUR [Book USD | -10.00 usd | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 usd|Transfer USD --> ' +
'EUR [Book EURO | 9.52 € | Open]')
self.assertEqual(
books[1].lines[0].rec_name,
'05/05/2022|from|9.52 €|Transfer USD --> ' +
'EUR [Book USD | -10.00 usd | Open]')
self.assertEqual(books[0].balance, Decimal('-10.0'))
self.assertEqual(books[0].currency.rec_name, 'usd')
self.assertEqual(books[1].balance, Decimal('9.52'))
@ -300,7 +312,6 @@ class LineTestCase(ModuleTestCase):
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()
@ -340,8 +351,10 @@ class LineTestCase(ModuleTestCase):
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(len(books[1].lines), 0)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|from|10.00 usd|Transfer USD <-- EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|from|10.00 usd|Transfer USD <-- ' +
'EUR [Book EURO | 0.00 € | Open]')
self.assertEqual(books[0].lines[0].reference, None)
self.assertEqual(len(books[0].lines[0].references), 0)
self.assertEqual(books[0].lines[0].reconciliation, None)
@ -353,10 +366,14 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(books[0].lines[0].reference, None)
self.assertEqual(len(books[0].lines[0].references), 1)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|from|10.00 usd|Transfer USD <-- EUR [Book EURO | -9.52 € | Open]')
self.assertEqual(books[1].lines[0].rec_name,
'05/05/2022|to|-9.52 €|Transfer USD <-- EUR [Book USD | 10.00 usd | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|from|10.00 usd|Transfer USD <-- ' +
'EUR [Book EURO | -9.52 € | Open]')
self.assertEqual(
books[1].lines[0].rec_name,
'05/05/2022|to|-9.52 €|Transfer USD <-- ' +
'EUR [Book USD | 10.00 usd | Open]')
self.assertEqual(books[0].balance, Decimal('10.0'))
self.assertEqual(books[0].currency.rec_name, 'usd')
self.assertEqual(books[1].balance, Decimal('-9.52'))
@ -371,7 +388,6 @@ class LineTestCase(ModuleTestCase):
pool = Pool()
Book = pool.get('cashbook.book')
Lines = pool.get('cashbook.line')
Reconciliation = pool.get('cashbook.recon')
Currency = pool.get('currency.currency')
CurrencyRate = pool.get('currency.currency.rate')
@ -427,8 +443,10 @@ class LineTestCase(ModuleTestCase):
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(len(books[1].lines), 0)
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 CHF|Transfer CHF --> USD [Book USD | 0.00 usd | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 CHF|Transfer CHF --> ' +
'USD [Book USD | 0.00 usd | Open]')
self.assertEqual(books[0].lines[0].reference, None)
self.assertEqual(len(books[0].lines[0].references), 0)
self.assertEqual(books[0].lines[0].reconciliation, None)
@ -445,10 +463,14 @@ class LineTestCase(ModuleTestCase):
# EUR | USD | CHF
# -----+-----+----- @ 05/02/2022
# 1.00| 1.05| 1.04
self.assertEqual(books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 CHF|Transfer CHF --> USD [Book USD | 10.10 usd | Open]')
self.assertEqual(books[1].lines[0].rec_name,
'05/05/2022|from|10.10 usd|Transfer CHF --> USD [Book CHF | -10.00 CHF | Open]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/05/2022|to|-10.00 CHF|Transfer CHF --> ' +
'USD [Book USD | 10.10 usd | Open]')
self.assertEqual(
books[1].lines[0].rec_name,
'05/05/2022|from|10.10 usd|Transfer CHF --> ' +
'USD [Book CHF | -10.00 CHF | Open]')
self.assertEqual(books[0].balance, Decimal('-10.0'))
self.assertEqual(books[0].currency.rec_name, 'Swiss Franc')
self.assertEqual(books[1].balance, Decimal('10.10'))
@ -507,68 +529,97 @@ class LineTestCase(ModuleTestCase):
}])
self.assertEqual(len(book.lines), 4)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].balance, Decimal('1.0'))
self.assertEqual(book.lines[0].reconciliation, None)
self.assertEqual(book.lines[0].state, 'edit')
self.assertEqual(book.lines[0].feature, 'gen')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].balance, Decimal('2.0'))
self.assertEqual(book.lines[1].reconciliation, None)
self.assertEqual(book.lines[1].state, 'edit')
self.assertEqual(book.lines[2].rec_name, '05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(
book.lines[2].rec_name,
'05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(book.lines[2].balance, Decimal('3.0'))
self.assertEqual(book.lines[2].reconciliation, None)
self.assertEqual(book.lines[2].state, 'edit')
self.assertEqual(book.lines[3].rec_name, '05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(
book.lines[3].rec_name,
'05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(book.lines[3].balance, Decimal('4.0'))
self.assertEqual(book.lines[3].reconciliation, None)
self.assertEqual(book.lines[3].state, 'edit')
Lines.wfcheck([book.lines[0], book.lines[1]])
recon, = Reconciliation.create([{
'cashbook': book.id,
}])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/02/2022 | 0.00 usd - 0.00 usd [0]')
'cashbook': book.id}])
self.assertEqual(
recon.rec_name,
'05/01/2022 - 05/02/2022 | 0.00 usd - 0.00 usd [0]')
Reconciliation.wfcheck([recon])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/02/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(
recon.rec_name,
'05/01/2022 - 05/02/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(len(book.lines), 4)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].balance, Decimal('1.0'))
self.assertEqual(book.lines[0].reconciliation.id, recon.id)
self.assertEqual(book.lines[0].state, 'check')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].balance, Decimal('2.0'))
self.assertEqual(book.lines[1].reconciliation.id, recon.id)
self.assertEqual(book.lines[1].state, 'check')
self.assertEqual(book.lines[2].rec_name, '05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(
book.lines[2].rec_name,
'05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(book.lines[2].balance, Decimal('3.0'))
self.assertEqual(book.lines[2].reconciliation, None)
self.assertEqual(book.lines[2].state, 'edit')
self.assertEqual(book.lines[3].rec_name, '05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(
book.lines[3].rec_name,
'05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(book.lines[3].balance, Decimal('4.0'))
self.assertEqual(book.lines[3].reconciliation, None)
self.assertEqual(book.lines[3].state, 'edit')
Reconciliation.wfdone([recon])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/02/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(
recon.rec_name,
'05/01/2022 - 05/02/2022 | 0.00 usd - 2.00 usd [2]')
self.assertEqual(len(book.lines), 4)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].balance, Decimal('1.0'))
self.assertEqual(book.lines[0].reconciliation.id, recon.id)
self.assertEqual(book.lines[0].state, 'done')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].balance, Decimal('2.0'))
self.assertEqual(book.lines[1].reconciliation.id, recon.id)
self.assertEqual(book.lines[1].state, 'done')
self.assertEqual(book.lines[2].rec_name, '05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(
book.lines[2].rec_name,
'05/15/2022|Rev|1.00 usd|Text 3 [Cat1]')
self.assertEqual(book.lines[2].balance, Decimal('3.0'))
self.assertEqual(book.lines[2].reconciliation, None)
self.assertEqual(book.lines[2].state, 'edit')
self.assertEqual(book.lines[3].rec_name, '05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(
book.lines[3].rec_name,
'05/17/2022|Rev|1.00 usd|Text 4 [Cat1]')
self.assertEqual(book.lines[3].balance, Decimal('4.0'))
self.assertEqual(book.lines[3].reconciliation, None)
self.assertEqual(book.lines[3].state, 'edit')
@ -588,8 +639,7 @@ class LineTestCase(ModuleTestCase):
company = self.prep_company()
party = self.prep_party()
with Transaction().set_context({
'company': company.id,
}):
'company': company.id}):
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
@ -620,10 +670,14 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.number_atcheck, False)
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|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
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|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
# add reconciliation
Book.write(*[
@ -637,8 +691,10 @@ class LineTestCase(ModuleTestCase):
}])
self.assertEqual(len(book.reconciliations), 1)
self.assertEqual(len(book.reconciliations[0].lines), 0)
self.assertEqual(book.reconciliations[0].date_from, date(2022, 5, 1))
self.assertEqual(book.reconciliations[0].date_to, date(2022, 5, 30))
self.assertEqual(
book.reconciliations[0].date_from, date(2022, 5, 1))
self.assertEqual(
book.reconciliations[0].date_to, date(2022, 5, 30))
self.assertEqual(book.reconciliations[0].state, 'edit')
Lines.wfcheck(book.lines)
@ -649,8 +705,12 @@ class LineTestCase(ModuleTestCase):
Reconciliation.wfcheck(book.reconciliations)
self.assertEqual(len(book.reconciliations[0].lines), 2)
self.assertEqual(book.reconciliations[0].lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.reconciliations[0].lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.reconciliations[0].lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.reconciliations[0].lines[1].rec_name,
'05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.reconciliations[0].lines[0].number, None)
self.assertEqual(book.reconciliations[0].lines[1].number, None)
@ -719,41 +779,62 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.state, 'open')
self.assertEqual(len(book.lines), 3)
self.assertEqual(book.lines[0].date, date(2022, 5, 1))
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
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|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[2].date, date(2022, 5, 3))
self.assertEqual(book.lines[2].rec_name, '05/03/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(
book.lines[2].rec_name, '05/03/2022|Rev/Sp|1.00 usd|Text 3 [-]')
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%')]), 3)
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%')]), 3)
# search in category of split-line
self.assertEqual(Lines.search_count([('rec_name', '=', 'sp-cat1')]), 1)
self.assertEqual(
Lines.search_count([('rec_name', '=', 'sp-cat1')]), 1)
# search in description of split-line
self.assertEqual(Lines.search_count([('rec_name', '=', 'text3-spline1')]), 1)
self.assertEqual(
Lines.search_count([('rec_name', '=', 'text3-spline1')]), 1)
# ilike fails in fields.Text to find subtext...
self.assertEqual(Lines.search_count([('rec_name', 'ilike', '%spline%')]), 0)
self.assertEqual(
Lines.search_count([('rec_name', 'ilike', '%spline%')]), 0)
# ...but it uses separator-chars
self.assertEqual(Lines.search_count([('rec_name', 'ilike', 'text3%')]), 1)
self.assertEqual(Lines.search_count([('rec_name', 'ilike', 'spline1')]), 1)
self.assertEqual(Lines.search_count([('rec_name', 'ilike', '%spline1')]), 1)
self.assertEqual(Lines.search_count([('rec_name', 'ilike', 'spline1%')]), 0)
self.assertEqual(Lines.search_count([('rec_name', 'ilike', 'text3')]), 1)
self.assertEqual(
Lines.search_count([('rec_name', 'ilike', 'text3%')]), 1)
self.assertEqual(
Lines.search_count([('rec_name', 'ilike', 'spline1')]), 1)
self.assertEqual(
Lines.search_count([('rec_name', 'ilike', '%spline1')]), 1)
self.assertEqual(
Lines.search_count([('rec_name', 'ilike', 'spline1%')]), 0)
self.assertEqual(
Lines.search_count([('rec_name', 'ilike', 'text3')]), 1)
self.assertEqual(Lines.search_count([('state_cashbook', '=', 'open')]), 3)
self.assertEqual(Lines.search_count([('state_cashbook', '=', 'closed')]), 0)
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'open')]), 3)
self.assertEqual(Lines.search_count([('cashbook.state', '=', 'closed')]), 0)
self.assertEqual(
Lines.search_count([('state_cashbook', '=', 'open')]), 3)
self.assertEqual(
Lines.search_count([('state_cashbook', '=', 'closed')]), 0)
self.assertEqual(
Lines.search_count([('cashbook.state', '=', 'open')]), 3)
self.assertEqual(
Lines.search_count([('cashbook.state', '=', 'closed')]), 0)
# sorting: date -> state -> id
self.assertEqual(len(book.lines), 3)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].state, 'edit')
self.assertEqual(book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name, '05/02/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].state, 'edit')
self.assertEqual(book.lines[2].rec_name, '05/03/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(
book.lines[2].rec_name, '05/03/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(book.lines[2].state, 'edit')
# set to same date
@ -764,21 +845,27 @@ class LineTestCase(ModuleTestCase):
}])
# check again
book, = Book.search([])
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].state, 'edit')
self.assertEqual(book.lines[1].rec_name, '05/01/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name, '05/01/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].state, 'edit')
self.assertEqual(book.lines[2].rec_name, '05/01/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(
book.lines[2].rec_name, '05/01/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(book.lines[2].state, 'edit')
# set to 'check', will sort first
Lines.wfcheck([book.lines[1]])
book, = Book.search([])
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[0].state, 'check')
self.assertEqual(book.lines[1].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[1].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[1].state, 'edit')
self.assertEqual(book.lines[2].rec_name, '05/01/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(
book.lines[2].rec_name, '05/01/2022|Rev/Sp|1.00 usd|Text 3 [-]')
self.assertEqual(book.lines[2].state, 'edit')
@with_transaction()
@ -791,7 +878,7 @@ class LineTestCase(ModuleTestCase):
category = self.prep_category(cattype='in')
company = self.prep_company()
party = self.prep_party()
self.prep_party()
book, = Book.create([{
'name': 'Book 1',
'btype': None,
@ -800,8 +887,10 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.state, 'open')
self.assertRaisesRegex(UserError,
'The value for field "Cashbook" in "Cashbook Line" is not valid according to its domain.',
self.assertRaisesRegex(
UserError,
'The value for field "Cashbook" in "Cashbook Line" is not ' +
'valid according to its domain.',
Line.create,
[{
'cashbook': book.id,
@ -817,7 +906,6 @@ class LineTestCase(ModuleTestCase):
"""
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
Party = pool.get('party.party')
types = self.prep_type()
@ -850,7 +938,8 @@ class LineTestCase(ModuleTestCase):
self.assertRaisesRegex(
UserError,
'The records could not be deleted because they are used by field "Party" of "Cashbook Line".',
'The records could not be deleted because they are used by ' +
'field "Party" of "Cashbook Line".',
Party.delete,
[party])
@ -901,8 +990,10 @@ class LineTestCase(ModuleTestCase):
Line.wfcheck([book.lines[0]])
self.assertEqual(book.lines[0].state, 'check')
self.assertRaisesRegex(UserError,
"The cashbook line '05/01/2022|1.00 usd|works [Cat1]' is 'Checked' and cannot be changed.",
self.assertRaisesRegex(
UserError,
"The cashbook line '05/01/2022|1.00 usd|works [Cat1]' is " +
"'Checked' and cannot be changed.",
Line.write,
*[
[book.lines[0]],
@ -914,8 +1005,10 @@ class LineTestCase(ModuleTestCase):
Book.wfclosed([book])
self.assertEqual(book.state, 'closed')
self.assertRaisesRegex(UserError,
"The cash book 'Book | 2.00 usd | Closed' is 'Closed' and cannot be changed.",
self.assertRaisesRegex(
UserError,
"The cash book 'Book | 2.00 usd | Closed' is 'Closed' " +
"and cannot be changed.",
Line.write,
*[
[book.lines[0]],
@ -999,13 +1092,12 @@ class LineTestCase(ModuleTestCase):
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
Category = pool.get('cashbook.category')
types = self.prep_type()
category_in = self.prep_category(cattype='in')
self.prep_category(cattype='in')
category_out = self.prep_category(name='Out Category', cattype='out')
company = self.prep_company()
party = self.prep_party()
self.prep_party()
book2, = Book.create([{
'name': 'Book 2',
@ -1035,32 +1127,43 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.rec_name, 'Book 1 | -1.00 usd | Open')
self.assertEqual(len(book.lines), 1)
self.assertEqual(len(book2.lines), 0)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Book 2 | 0.00 usd | Open]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|to|-1.00 usd|Transfer Out [Book 2 | 0.00 usd | Open]')
self.assertEqual(len(book.lines[0].references), 0)
# check counterpart
self.assertEqual(book.lines[0].booktransf.rec_name, 'Book 2 | 0.00 usd | Open')
self.assertEqual(
book.lines[0].booktransf.rec_name,
'Book 2 | 0.00 usd | Open')
self.assertEqual(book.lines[0].booktransf.btype.feature, 'gen')
self.assertEqual(book.lines[0].booktransf_feature, 'gen')
# check payee
self.assertEqual(book.lines[0].payee.rec_name, 'Book 2 | 0.00 usd | Open')
self.assertEqual(
book.lines[0].payee.rec_name, 'Book 2 | 0.00 usd | Open')
self.assertEqual(Line.search_count([('payee', 'ilike', 'book 2%')]), 1)
# set line to 'checked', this creates the counterpart
Line.wfcheck(list(book.lines))
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Book 2 | 1.00 usd | Open]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|to|-1.00 usd|Transfer Out [Book 2 | 1.00 usd | Open]')
self.assertEqual(book.lines[0].state, 'check')
self.assertEqual(len(book.lines[0].references), 1)
self.assertEqual(book.lines[0].reference, None)
self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id)
self.assertEqual(len(book2.lines), 1)
self.assertEqual(book2.lines[0].rec_name, '05/01/2022|from|1.00 usd|Transfer Out [Book 1 | -1.00 usd | Open]')
self.assertEqual(
book2.lines[0].rec_name,
'05/01/2022|from|1.00 usd|Transfer Out [Book 1 | -1.00 usd | Open]')
self.assertEqual(book2.lines[0].state, 'check')
self.assertEqual(book2.lines[0].reference.rec_name, '05/01/2022|to|-1.00 usd|Transfer Out [Book 2 | 1.00 usd | Open]')
self.assertEqual(
book2.lines[0].reference.rec_name,
'05/01/2022|to|-1.00 usd|Transfer Out [Book 2 | 1.00 usd | Open]')
self.assertEqual(len(book2.lines[0].references), 0)
@with_transaction()
@ -1070,13 +1173,12 @@ class LineTestCase(ModuleTestCase):
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
Category = pool.get('cashbook.category')
types = self.prep_type()
category_in = self.prep_category(cattype='in')
category_out = self.prep_category(name='Out Category', cattype='out')
self.prep_category(name='Out Category', cattype='out')
company = self.prep_company()
party = self.prep_party()
self.prep_party()
book2, = Book.create([{
'name': 'Book 2',
@ -1106,28 +1208,39 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.rec_name, 'Book 1 | 1.00 usd | Open')
self.assertEqual(len(book.lines), 1)
self.assertEqual(len(book2.lines), 0)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|from|1.00 usd|Transfer In [Book 2 | 0.00 usd | Open]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|from|1.00 usd|Transfer In [Book 2 | 0.00 usd | Open]')
self.assertEqual(len(book.lines[0].references), 0)
# set line to 'checked', this creates the counterpart
Line.wfcheck(list(book.lines))
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|from|1.00 usd|Transfer In [Book 2 | -1.00 usd | Open]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|from|1.00 usd|Transfer In [Book 2 | -1.00 usd | Open]')
self.assertEqual(book.lines[0].state, 'check')
self.assertEqual(len(book.lines[0].references), 1)
self.assertEqual(book.lines[0].reference, None)
self.assertEqual(book.lines[0].references[0].id, book2.lines[0].id)
self.assertEqual(len(book2.lines), 1)
self.assertEqual(book2.lines[0].rec_name, '05/01/2022|to|-1.00 usd|Transfer In [Book 1 | 1.00 usd | Open]')
self.assertEqual(
book2.lines[0].rec_name,
'05/01/2022|to|-1.00 usd|Transfer In [Book 1 | 1.00 usd | Open]')
self.assertEqual(book2.lines[0].state, 'check')
self.assertEqual(book2.lines[0].reference.rec_name, '05/01/2022|from|1.00 usd|Transfer In [Book 2 | -1.00 usd | Open]')
self.assertEqual(
book2.lines[0].reference.rec_name,
'05/01/2022|from|1.00 usd|Transfer In [Book 2 | -1.00 usd | Open]')
self.assertEqual(len(book2.lines[0].references), 0)
# tryt wfedit to 'book2.lines[0]'
self.assertRaisesRegex(UserError,
"The current line is managed by the cashbook line '05/01/2022|from|1.00 usd|Transfer In [Book 2 | -1.00 usd | Open]', cashbook: 'Book 1 | 1.00 usd | Open'.",
self.assertRaisesRegex(
UserError,
"The current line is managed by the cashbook line " +
"'05/01/2022|from|1.00 usd|Transfer In [Book 2 | -1.00 usd " +
"| Open]', cashbook: 'Book 1 | 1.00 usd | Open'.",
Line.wfedit,
[book2.lines[0]])
@ -1141,8 +1254,6 @@ class LineTestCase(ModuleTestCase):
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
Configuration = pool.get('cashbook.configuration')
Category = pool.get('cashbook.category')
types = self.prep_type()
category_in = self.prep_category(cattype='in')
@ -1289,18 +1400,16 @@ class LineTestCase(ModuleTestCase):
"""
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
Configuration = pool.get('cashbook.configuration')
Category = pool.get('cashbook.category')
types = self.prep_type()
category = self.prep_category(cattype='in')
self.prep_category(cattype='in')
company = self.prep_company()
party = self.prep_party()
with Transaction().set_context({
'company': company.id,
}):
'company': company.id}):
category2, = Category.create([{
'company': company.id,
@ -1442,8 +1551,11 @@ class LineTestCase(ModuleTestCase):
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 | 2.00 usd | Closed' is in state 'Closed'.",
self.assertRaisesRegex(
UserError,
"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]])
@ -1490,8 +1602,10 @@ class LineTestCase(ModuleTestCase):
Lines.wfcheck([book.lines[0]])
self.assertEqual(book.lines[0].state, 'check')
self.assertRaisesRegex(UserError,
"The cashbook line '05/01/2022|1.00 usd|Test 1 [Cat1]' cannot be deleted, its in state 'Checked'.",
self.assertRaisesRegex(
UserError,
"The cashbook line '05/01/2022|1.00 usd|Test 1 [Cat1]' " +
"cannot be deleted, its in state 'Checked'.",
Lines.delete,
[book.lines[0]])
@ -1548,8 +1662,7 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'diego' , try access
with Transaction().set_user(usr_lst[1].id):
lines = Line.search([])
@ -1559,20 +1672,28 @@ 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 | 1.00 usd | Open')
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
self.assertEqual(
lines[0].cashbook.rec_name,
'Fridas book | 1.00 usd | Open')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
Line.write(*[
lines,
{
'description': 'Test 2',
}])
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
self.assertEqual(lines[0].owner_cashbook.rec_name, 'Frida')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
self.assertEqual(
lines[0].owner_cashbook.rec_name, 'Frida')
@with_transaction()
def test_line_permission_reviewer(self):
""" create book+line + 2x users + 1x reviewer-group, add users to group, check access
""" create book+line + 2x users + 1x reviewer-group,
add users to group, check access
"""
pool = Pool()
ResUser = pool.get('res.user')
@ -1630,37 +1751,47 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'diego' , try access
with Transaction().set_user(usr_lst[1].id):
lines = Line.search([])
self.assertEqual(len(lines), 1)
self.assertEqual(len(lines[0].cashbook.reviewer.users), 1)
self.assertEqual(lines[0].cashbook.reviewer.users[0].rec_name, 'Diego')
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
self.assertEqual(
lines[0].cashbook.reviewer.users[0].rec_name,
'Diego')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
Line.write(*[
lines,
{
'description': 'Test 2',
}])
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
# change to user 'frida' read/write line
with Transaction().set_user(usr_lst[0].id):
lines = Line.search([])
self.assertEqual(len(lines), 1)
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
Line.write(*[
lines,
{
'description': 'Test 3',
}])
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 3 [Cat1]')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 3 [Cat1]')
@with_transaction()
def test_line_permission_observer(self):
""" create book+line + 2x users + 1x observer-group, add users to group, check access
""" create book+line + 2x users + 1x observer-group,
add users to group, check access
"""
pool = Pool()
ResUser = pool.get('res.user')
@ -1718,18 +1849,25 @@ class LineTestCase(ModuleTestCase):
self.assertEqual(book.owner.rec_name, 'Frida'),
with Transaction().set_context({
'_check_access': True,
}):
'_check_access': True}):
# change to user 'diego' , try access
with Transaction().set_user(usr_lst[1].id):
lines = Line.search([])
self.assertEqual(len(lines), 1)
self.assertEqual(len(lines[0].cashbook.observer.users), 1)
self.assertEqual(lines[0].cashbook.observer.users[0].rec_name, 'Diego')
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
self.assertEqual(
lines[0].cashbook.observer.users[0].rec_name,
'Diego')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
self.assertRaisesRegex(UserError,
'You are not allowed to write to records "[0-9]{1,}" of "Cashbook Line" because of at least one of these rules:\nOwners and reviewers: Cashbook line write - ',
self.assertRaisesRegex(
UserError,
'You are not allowed to write to records ' +
'"[0-9]{1,}" of "Cashbook Line" because of at least ' +
'one of these rules:\nOwners and reviewers: ' +
'Cashbook line write - ',
Line.write,
*[
lines,
@ -1742,12 +1880,16 @@ class LineTestCase(ModuleTestCase):
with Transaction().set_user(usr_lst[0].id):
lines = Line.search([])
self.assertEqual(len(lines), 1)
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 1 [Cat1]')
Line.write(*[
lines,
{
'description': 'Test 2',
}])
self.assertEqual(lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
self.assertEqual(
lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Test 2 [Cat1]')
# end LineTestCase

View file

@ -5,7 +5,6 @@
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
from decimal import Decimal
@ -24,7 +23,7 @@ class ReconTestCase(ModuleTestCase):
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
category = self.prep_category(cattype='in')
self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -41,18 +40,21 @@ class ReconTestCase(ModuleTestCase):
}])
Book.write(*[
[book],
{
'reconciliations': [('create', [{
[book], {'reconciliations': [('create', [{
'date': date(2022, 6, 1),
'date_from': date(2022, 6, 1),
'date_to': date(2022, 6, 30),
}])],
}])
self.assertEqual(book.reconciliations[0].rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(book.reconciliations[1].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[0].rec_name,
'05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[1].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'The date range overlaps with another reconciliation.',
Reconciliation.write,
*[
@ -72,7 +74,7 @@ class ReconTestCase(ModuleTestCase):
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
category = self.prep_category(cattype='in')
self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -89,18 +91,21 @@ class ReconTestCase(ModuleTestCase):
}])
Book.write(*[
[book],
{
'reconciliations': [('create', [{
[book], {'reconciliations': [('create', [{
'date': date(2022, 6, 1),
'date_from': date(2022, 6, 1),
'date_to': date(2022, 6, 30),
}])],
}])
self.assertEqual(book.reconciliations[0].rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(book.reconciliations[1].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[0].rec_name,
'05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[1].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'The date range overlaps with another reconciliation.',
Reconciliation.write,
*[
@ -119,7 +124,7 @@ class ReconTestCase(ModuleTestCase):
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
category = self.prep_category(cattype='in')
self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -136,18 +141,21 @@ class ReconTestCase(ModuleTestCase):
}])
Book.write(*[
[book],
{
'reconciliations': [('create', [{
[book], {'reconciliations': [('create', [{
'date': date(2022, 6, 1),
'date_from': date(2022, 6, 1),
'date_to': date(2022, 6, 30),
}])],
}])
self.assertEqual(book.reconciliations[0].rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(book.reconciliations[1].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[0].rec_name,
'05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[1].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'The date range overlaps with another reconciliation.',
Reconciliation.write,
*[
@ -167,7 +175,7 @@ class ReconTestCase(ModuleTestCase):
Reconciliation = pool.get('cashbook.recon')
types = self.prep_type()
category = self.prep_category(cattype='in')
self.prep_category(cattype='in')
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
@ -184,18 +192,21 @@ class ReconTestCase(ModuleTestCase):
}])
Book.write(*[
[book],
{
'reconciliations': [('create', [{
[book], {'reconciliations': [('create', [{
'date': date(2022, 6, 1),
'date_from': date(2022, 6, 1),
'date_to': date(2022, 6, 30),
}])],
}])
self.assertEqual(book.reconciliations[0].rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(book.reconciliations[1].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[0].rec_name,
'05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[1].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
self.assertRaisesRegex(UserError,
self.assertRaisesRegex(
UserError,
'The date range overlaps with another reconciliation.',
Reconciliation.write,
*[
@ -230,11 +241,15 @@ class ReconTestCase(ModuleTestCase):
}])],
}])
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]')
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].feature, 'gen')
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].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
@with_transaction()
def test_recon_set_start_amount_by_predecessor(self):
@ -279,14 +294,18 @@ class ReconTestCase(ModuleTestCase):
}])
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(
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 | 0.00 usd - 12.00 usd [2]')
self.assertEqual(
book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 12.00 usd [2]')
Reconciliation.wfdone(list(book.reconciliations))
self.assertEqual(book.reconciliations[0].state, 'done')
@ -295,9 +314,13 @@ class ReconTestCase(ModuleTestCase):
'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]')
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 | 12.00 usd - 12.00 usd [0]')
self.assertEqual(
recons[0].rec_name,
'05/31/2022 - 06/30/2022 | 12.00 usd - 12.00 usd [0]')
@with_transaction()
def test_recon_predecessor_done(self):
@ -325,7 +348,9 @@ class ReconTestCase(ModuleTestCase):
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].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([{
@ -333,14 +358,20 @@ class ReconTestCase(ModuleTestCase):
'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]'.",
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_to(self):
""" create reconciliation, check: set date_to to last date of checked-line
""" create reconciliation, check:
set date_to to last date of checked-line
"""
pool = Pool()
Book = pool.get('cashbook.book')
@ -383,10 +414,14 @@ class ReconTestCase(ModuleTestCase):
'date_to': date(2022, 5, 31),
}])
# dates are updates by .create()
self.assertEqual(recon.rec_name, '05/01/2022 - 05/18/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
recon.rec_name,
'05/01/2022 - 05/18/2022 | 0.00 usd - 0.00 usd [0]')
Reconciliation.wfcheck([recon])
self.assertEqual(recon.rec_name, '05/01/2022 - 05/18/2022 | 0.00 usd - 15.00 usd [2]')
self.assertEqual(
recon.rec_name,
'05/01/2022 - 05/18/2022 | 0.00 usd - 15.00 usd [2]')
@with_transaction()
def test_recon_autoset_date_from(self):
@ -417,7 +452,8 @@ class ReconTestCase(ModuleTestCase):
Reconciliation.wfdone([book.reconciliations[0]])
# date_from is corrected by .create() to start_date of book
self.assertEqual(book.reconciliations[0].rec_name,
self.assertEqual(
book.reconciliations[0].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]')
r2, = Reconciliation.create([{
@ -425,7 +461,9 @@ class ReconTestCase(ModuleTestCase):
'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]')
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(*[
@ -433,10 +471,15 @@ class ReconTestCase(ModuleTestCase):
{
'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.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.",
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])
@ -484,14 +527,23 @@ class ReconTestCase(ModuleTestCase):
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|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[1].rec_name, '05/05/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'05/05/2022|Rev|1.00 usd|Text 2 [Cat1]')
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(
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)
self.assertRaisesRegex(UserError,
"For reconciliation, the line '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]' must be in the status 'Check' or 'Done'.",
self.assertRaisesRegex(
UserError,
"For reconciliation, the line " +
"'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]' must be in the " +
"status 'Check' or 'Done'.",
Lines.write,
*[
[book.lines[0]],
@ -508,8 +560,11 @@ class ReconTestCase(ModuleTestCase):
}])
self.assertEqual(len(book.reconciliations[0].lines), 2)
self.assertRaisesRegex(UserError,
"The status cannot be changed to 'Edit' as long as the line '05/01/2022|1.00 usd|Text 1 [Cat1]' is associated with a reconciliation.",
self.assertRaisesRegex(
UserError,
"The status cannot be changed to 'Edit' as long as the line " +
"'05/01/2022|1.00 usd|Text 1 [Cat1]' is associated " +
"with a reconciliation.",
Lines.wfedit,
[book.lines[0]])
@ -533,10 +588,16 @@ class ReconTestCase(ModuleTestCase):
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|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.reconciliations[0].lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].state, 'check')
self.assertEqual(book.lines[1].rec_name, '06/01/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'06/01/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[1].state, 'edit')
# move 1st line into date-range of checked-reconciliation, wf-check
@ -545,8 +606,10 @@ class ReconTestCase(ModuleTestCase):
{
'date': date(2022, 5, 20),
}])
self.assertRaisesRegex(UserError,
"For the date '05/20/2022' there is already a completed reconciliation. Use a different date.",
self.assertRaisesRegex(
UserError,
"For the date '05/20/2022' there is already a completed " +
"reconciliation. Use a different date.",
Lines.wfcheck,
[book.lines[1]])
@ -557,7 +620,7 @@ class ReconTestCase(ModuleTestCase):
{
'date': date(2022, 5, 31),
}])
Lines.wfcheck([book.lines[1]]) # ok
Lines.wfcheck([book.lines[1]]) # ok
Lines.wfedit([book.lines[1]])
Lines.write(*[
[book.lines[1]],
@ -571,8 +634,12 @@ class ReconTestCase(ModuleTestCase):
'date_from': date(2022, 5, 31),
'date_to': date(2022, 6, 30),
}])
self.assertEqual(book.reconciliations[0].rec_name, '05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(book.reconciliations[1].rec_name, '05/01/2022 - 05/31/2022 | 0.00 usd - 1.00 usd [1]')
self.assertEqual(
book.reconciliations[0].rec_name,
'05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0]')
self.assertEqual(
book.reconciliations[1].rec_name,
'05/01/2022 - 05/31/2022 | 0.00 usd - 1.00 usd [1]')
Reconciliation.wfdone([book.reconciliations[1]])
Reconciliation.wfcheck([recon2])
@ -581,8 +648,10 @@ class ReconTestCase(ModuleTestCase):
{
'date': date(2022, 5, 31),
}])
self.assertRaisesRegex(UserError,
"For the date '05/31/2022' there is already a completed reconciliation. Use a different date.",
self.assertRaisesRegex(
UserError,
"For the date '05/31/2022' there is already a completed " +
"reconciliation. Use a different date.",
Lines.wfcheck,
[book.lines[1]])
@ -630,13 +699,19 @@ class ReconTestCase(ModuleTestCase):
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|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[1].rec_name, '06/05/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'06/05/2022|Rev|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|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.reconciliations[0].lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
Lines.write(*[
[book.lines[1]],
@ -644,8 +719,11 @@ class ReconTestCase(ModuleTestCase):
'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.",
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]])
@ -691,20 +769,27 @@ class ReconTestCase(ModuleTestCase):
self.assertEqual(len(book.reconciliations), 1)
self.assertEqual(len(book.reconciliations[0].lines), 1)
self.assertRaisesRegex(UserError,
"The reconciliation '05/01/2022 - 05/31/2022 | 0.00 - 0.00 usd [0]' cannot be deleted, its in state 'Check'.",
self.assertRaisesRegex(
UserError,
"The reconciliation '05/01/2022 - 05/31/2022 " +
"| 0.00 - 0.00 usd [0]' cannot be deleted, its in state 'Check'.",
Reconciliation.delete,
list(book.reconciliations))
Book.wfclosed([book])
self.assertRaisesRegex(UserError,
"The cashbook line '05/01/2022 - 05/31/2022: 0.00 usd' cannot be deleted because the Cashbook 'Book 1 | 1.00 usd | Closed' is in state 'Closed'.",
self.assertRaisesRegex(
UserError,
"The cashbook line '05/01/2022 - 05/31/2022: 0.00 usd' " +
"cannot be deleted because the Cashbook " +
"'Book 1 | 1.00 usd | Closed' is in state 'Closed'.",
Reconciliation.delete,
list(book.reconciliations))
self.assertRaisesRegex(UserError,
"The cash book 'Book 1 | 1.00 usd | Closed' is 'Closed' and cannot be changed.",
self.assertRaisesRegex(
UserError,
"The cash book 'Book 1 | 1.00 usd | Closed' is 'Closed' " +
"and cannot be changed.",
Reconciliation.write,
*[
list(book.reconciliations),
@ -757,17 +842,27 @@ class ReconTestCase(ModuleTestCase):
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|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[1].rec_name, '05/05/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[1].rec_name,
'05/05/2022|Rev|1.00 usd|Text 2 [Cat1]')
self.assertEqual(book.lines[0].reconciliation, None)
self.assertEqual(book.lines[1].reconciliation, None)
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(
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)
# run wf, fail with lines not 'checked'
self.assertRaisesRegex(UserError,
"For the reconciliation '05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0]' of the cashbook 'Book 1 | 2.00 usd | Open', all lines in the date range from '05/01/2022' to '05/31/2022' must be in the 'Check' state.",
self.assertRaisesRegex(
UserError,
"For the reconciliation '05/01/2022 - 05/31/2022 | " +
"0.00 usd - 0.00 usd [0]' of the cashbook " +
"'Book 1 | 2.00 usd | Open', all lines in the date range " +
"from '05/01/2022' to '05/31/2022' must be in the 'Check' state.",
Reconciliation.wfcheck,
list(book.reconciliations),
)
@ -776,8 +871,12 @@ 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 - 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]')
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))

View file

@ -5,10 +5,7 @@
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
from unittest.mock import MagicMock
from decimal import Decimal
@ -22,12 +19,11 @@ class SplitLineTestCase(ModuleTestCase):
"""
pool = Pool()
Book = pool.get('cashbook.book')
Line = pool.get('cashbook.line')
types = self.prep_type()
category1 = self.prep_category(cattype='in')
company = self.prep_company()
party = self.prep_party()
self.prep_party()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
@ -59,7 +55,9 @@ class SplitLineTestCase(ModuleTestCase):
}])],
}])
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev/Sp|11.00 usd|- [-]')
self.assertEqual(book.lines[0].category, None)
self.assertEqual(len(book.lines[0].splitlines), 2)
@ -68,9 +66,11 @@ class SplitLineTestCase(ModuleTestCase):
self.assertEqual(book.lines[0].splitlines[1].feature, 'gen')
self.assertEqual(book.lines[0].splitlines[1].booktransf_feature, None)
self.assertEqual(book.lines[0].splitlines[0].rec_name,
self.assertEqual(
book.lines[0].splitlines[0].rec_name,
'Rev/Sp|5.00 usd|from category [Cat1]')
self.assertEqual(book.lines[0].splitlines[1].rec_name,
self.assertEqual(
book.lines[0].splitlines[1].rec_name,
'Rev/Sp|6.00 usd|from cashbook [Cat1]')
@with_transaction()
@ -111,7 +111,9 @@ class SplitLineTestCase(ModuleTestCase):
}])
self.assertEqual(books[0].rec_name, 'Book 1 | 1.00 usd | Open')
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(books[1].rec_name, 'Book 2 | 0.00 usd | Open')
Book.write(*[
@ -133,20 +135,26 @@ class SplitLineTestCase(ModuleTestCase):
})]
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|Text 1 [-]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/01/2022|Rev/Sp|11.00 usd|Text 1 [-]')
self.assertEqual(books[0].lines[0].category, None)
self.assertEqual(len(books[0].lines[0].splitlines), 2)
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
self.assertEqual(
books[0].lines[0].splitlines[0].rec_name,
'Rev/Sp|5.00 usd|from category [Cat1]')
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
self.assertEqual(
books[0].lines[0].splitlines[1].rec_name,
'Rev/Sp|6.00 usd|from cashbook [Book 2 | 0.00 usd | Open]')
self.assertEqual(len(books[1].lines), 0)
self.assertEqual(books[0].lines[0].splitlines[0].feature, 'gen')
self.assertEqual(books[0].lines[0].splitlines[0].feature, 'gen')
self.assertEqual(books[0].lines[0].splitlines[0].booktransf_feature, None)
self.assertEqual(
books[0].lines[0].splitlines[0].booktransf_feature, None)
self.assertEqual(books[0].lines[0].splitlines[1].feature, 'gen')
self.assertEqual(books[0].lines[0].splitlines[1].booktransf_feature, 'gen')
self.assertEqual(
books[0].lines[0].splitlines[1].booktransf_feature, 'gen')
# wf: edit -> check
Line.wfcheck(books[0].lines)
@ -154,13 +162,16 @@ class SplitLineTestCase(ModuleTestCase):
self.assertEqual(books[0].lines[0].state, 'check')
self.assertEqual(books[0].lines[0].number, '1')
self.assertEqual(len(books[0].lines[0].references), 1)
self.assertEqual(books[0].lines[0].references[0].rec_name,
self.assertEqual(
books[0].lines[0].references[0].rec_name,
'05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open]')
self.assertEqual(len(books[1].lines), 1)
self.assertEqual(books[1].lines[0].reference.rec_name,
self.assertEqual(
books[1].lines[0].reference.rec_name,
'05/01/2022|Rev/Sp|11.00 usd|Text 1 [-]')
self.assertEqual(books[1].lines[0].rec_name,
self.assertEqual(
books[1].lines[0].rec_name,
'05/01/2022|to|-6.00 usd|from cashbook [Book 1 | 11.00 usd | Open]')
# wf: check --> edit
@ -209,7 +220,9 @@ class SplitLineTestCase(ModuleTestCase):
}])
self.assertEqual(books[0].rec_name, 'Book 1 | -1.00 € | Open')
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Exp|-1.00 €|Text 1 [Cat1]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/01/2022|Exp|-1.00 €|Text 1 [Cat1]')
self.assertEqual(books[1].rec_name, 'Book 2 | 0.00 usd | Open')
# EUR --> USD
@ -232,15 +245,22 @@ class SplitLineTestCase(ModuleTestCase):
})]
}])
self.assertEqual(len(books[0].lines), 1)
self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 €|Text 1 [-]')
self.assertEqual(
books[0].lines[0].rec_name,
'05/01/2022|Exp/Sp|-11.00 €|Text 1 [-]')
self.assertEqual(books[0].lines[0].category, None)
self.assertEqual(len(books[0].lines[0].splitlines), 2)
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
self.assertEqual(
books[0].lines[0].splitlines[0].rec_name,
'Exp/Sp|5.00 €|to category [Cat1]')
self.assertEqual(books[0].lines[0].splitlines[0].amount_2nd_currency, None)
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
self.assertEqual(
books[0].lines[0].splitlines[0].amount_2nd_currency, None)
self.assertEqual(
books[0].lines[0].splitlines[1].rec_name,
'Exp/Sp|6.00 €|to book2 [Book 2 | 0.00 usd | Open]')
self.assertEqual(books[0].lines[0].splitlines[1].amount_2nd_currency, Decimal('6.3'))
self.assertEqual(
books[0].lines[0].splitlines[1].amount_2nd_currency,
Decimal('6.3'))
self.assertEqual(len(books[1].lines), 0)
# wf: edit -> check
@ -249,16 +269,21 @@ class SplitLineTestCase(ModuleTestCase):
self.assertEqual(books[0].lines[0].state, 'check')
self.assertEqual(books[0].lines[0].number, '1')
self.assertEqual(len(books[0].lines[0].references), 1)
self.assertEqual(books[0].lines[0].references[0].rec_name,
self.assertEqual(
books[0].lines[0].references[0].rec_name,
'05/01/2022|from|6.30 usd|to book2 [Book 1 | -11.00 € | Open]')
self.assertEqual(len(books[1].lines), 1)
self.assertEqual(books[1].lines[0].reference.rec_name,
self.assertEqual(
books[1].lines[0].reference.rec_name,
'05/01/2022|Exp/Sp|-11.00 €|Text 1 [-]')
self.assertEqual(books[1].lines[0].rec_name,
self.assertEqual(
books[1].lines[0].rec_name,
'05/01/2022|from|6.30 usd|to book2 [Book 1 | -11.00 € | Open]')
self.assertEqual(books[1].lines[0].amount, Decimal('6.3'))
self.assertEqual(books[1].lines[0].amount_2nd_currency, Decimal('6.0'))
self.assertEqual(
books[1].lines[0].amount, Decimal('6.3'))
self.assertEqual(
books[1].lines[0].amount_2nd_currency, Decimal('6.0'))
# wf: check --> edit
Line.wfedit(books[0].lines)
@ -298,7 +323,9 @@ class SplitLineTestCase(ModuleTestCase):
}])
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
self.assertEqual(book.lines[0].amount, Decimal('1.0'))
self.assertEqual(book.lines[0].category.rec_name, 'Cat1')
@ -317,7 +344,9 @@ class SplitLineTestCase(ModuleTestCase):
}])],
}])
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev/Sp|7.00 usd|Text 1 [-]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev/Sp|7.00 usd|Text 1 [-]')
self.assertEqual(book.lines[0].amount, Decimal('7.0'))
self.assertEqual(book.lines[0].category, None)
@ -325,21 +354,26 @@ class SplitLineTestCase(ModuleTestCase):
self.assertEqual(book.lines[0].splitlines[0].amount, Decimal('5.0'))
self.assertEqual(book.lines[0].splitlines[0].category.rec_name, 'Cat1')
self.assertEqual(book.lines[0].splitlines[0].description, 'line 1')
self.assertEqual(book.lines[0].splitlines[0].rec_name, 'Rev/Sp|5.00 usd|line 1 [Cat1]')
self.assertEqual(
book.lines[0].splitlines[0].rec_name,
'Rev/Sp|5.00 usd|line 1 [Cat1]')
self.assertEqual(book.lines[0].splitlines[1].amount, Decimal('2.0'))
self.assertEqual(book.lines[0].splitlines[1].category.rec_name, 'Cat2')
self.assertEqual(book.lines[0].splitlines[1].description, 'line 2')
self.assertEqual(book.lines[0].splitlines[1].rec_name, 'Rev/Sp|2.00 usd|line 2 [Cat2]')
self.assertEqual(
book.lines[0].splitlines[1].rec_name,
'Rev/Sp|2.00 usd|line 2 [Cat2]')
Lines.write(*[
[book.lines[0]],
{
'splitlines': [('write',
[book.lines[0].splitlines[0]],
{
'amount': Decimal('3.5'),
})],
'splitlines': [
('write',
[book.lines[0].splitlines[0]],
{
'amount': Decimal('3.5'),
})],
}])
self.assertEqual(book.lines[0].splitlines[0].amount, Decimal('3.5'))
self.assertEqual(book.lines[0].splitlines[1].amount, Decimal('2.0'))
@ -352,7 +386,9 @@ class SplitLineTestCase(ModuleTestCase):
'amount': Decimal('7.5'),
'category': category2.id,
}])
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|7.50 usd|Text 1 [Cat2]')
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Rev|7.50 usd|Text 1 [Cat2]')
self.assertEqual(book.lines[0].category.rec_name, 'Cat2')
self.assertEqual(len(book.lines[0].splitlines), 0)

37
tests/test_module.py Normal file
View file

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# This file is part of the cashbook-module from m-ds for Tryton.
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase
from .type import TypeTestCase
from .book import BookTestCase
from .line import LineTestCase
from .splitline import SplitLineTestCase
from .config import ConfigTestCase
from .category import CategoryTestCase
from .reconciliation import ReconTestCase
from .bookingwiz import BookingWizardTestCase
from .currency import CurrencyTestCase
class CashbookTestCase(
CurrencyTestCase,
BookingWizardTestCase,
ReconTestCase,
CategoryTestCase,
ConfigTestCase,
LineTestCase,
SplitLineTestCase,
BookTestCase,
TypeTestCase,
ModuleTestCase):
'Test cashbook module'
module = 'cashbook'
# end CashbookTestCase
del ModuleTestCase

View file

@ -3,16 +3,15 @@
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.tests.test_tryton import with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.exceptions import UserError
class TypeTestCase(ModuleTestCase):
'Test cashbook type module'
module = 'cashbook'
class TypeTestCase(object):
""" test types
"""
def prep_type(self, name='Cash', short='CAS'):
""" create book-type
"""