2022-08-28 20:16:34 +00:00
|
|
|
# -*- 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, with_transaction
|
|
|
|
from trytond.pool import Pool
|
|
|
|
from trytond.transaction import Transaction
|
|
|
|
from trytond.modules.cashbook.tests import CashbookTestCase
|
|
|
|
from .qifdata import qif_category, qif_types
|
|
|
|
|
|
|
|
|
|
|
|
class CategoryTestCase(CashbookTestCase):
|
|
|
|
'Test cashbook categoy module'
|
|
|
|
module = 'CashbookExchangeTestCase'
|
|
|
|
|
2022-08-30 20:49:52 +00:00
|
|
|
@with_transaction()
|
|
|
|
def test_wiz_import_category(self):
|
|
|
|
""" create categories by run wizard
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Category = pool.get('cashbook.category')
|
|
|
|
ImportWiz = pool.get('cashbook_dataexchange.qif_imp_wiz', type='wizard')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
with Transaction().set_context({
|
|
|
|
'company': company.id,
|
|
|
|
'active_model': 'cashbook.category',
|
|
|
|
}):
|
|
|
|
(sess_id, start_state, end_state) = ImportWiz.create()
|
|
|
|
w_obj = ImportWiz(sess_id)
|
|
|
|
self.assertEqual(start_state, 'start')
|
|
|
|
self.assertEqual(end_state, 'end')
|
|
|
|
|
|
|
|
# run start
|
|
|
|
result = ImportWiz.execute(sess_id, {}, start_state)
|
|
|
|
self.assertEqual(list(result.keys()), ['view'])
|
|
|
|
self.assertEqual(result['view']['defaults']['company'], company.id)
|
|
|
|
|
|
|
|
r1 = {}
|
|
|
|
r1['file_'] = qif_types.encode('utf8')
|
|
|
|
r1['company'] = company.id
|
|
|
|
w_obj.start.file_ = r1['file_']
|
|
|
|
w_obj.start.company = company.id
|
|
|
|
|
|
|
|
result = ImportWiz.execute(sess_id, {'start': r1}, 'readf')
|
|
|
|
|
|
|
|
self.assertEqual(list(result.keys()), ['view'])
|
|
|
|
self.assertEqual(result['view']['defaults']['company'], company.id)
|
|
|
|
self.assertEqual(result['view']['defaults']['info'],
|
|
|
|
"""The following categories are now imported:\\n
|
|
|
|
Gehalt (in)
|
|
|
|
Gehalt/Zulagen (in)
|
|
|
|
|
|
|
|
Telekommunikation (out)
|
|
|
|
Telekommunikation/Online-Dienste (out)
|
|
|
|
Telekommunikation/Telefon (out)
|
|
|
|
Telekommunikation/Telefon/Test1 (out)
|
|
|
|
Telekommunikation/Fernsehen (out)
|
|
|
|
Telefon (out)
|
|
|
|
Telefon/Telco1-Tablett (out)
|
|
|
|
Telefon/Telco2-Handy (out)
|
|
|
|
Telefon/Telco3 (out)
|
|
|
|
Fernsehen (out)
|
|
|
|
Fernsehen/TV-Company (out)
|
|
|
|
Fernsehen/GEZ (out)
|
|
|
|
Lebensmittel (out)""")
|
|
|
|
|
|
|
|
ImportWiz.delete(sess_id)
|
|
|
|
|
|
|
|
|
2022-08-28 20:16:34 +00:00
|
|
|
@with_transaction()
|
|
|
|
def test_category_create_by_qif_emptydb(self):
|
|
|
|
""" create categories by import a qif-file
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Category = pool.get('cashbook.category')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
with Transaction().set_context({
|
|
|
|
'company': company.id,
|
|
|
|
}):
|
|
|
|
records = Category.create_from_qif(qif_types)
|
|
|
|
|
2022-08-30 20:49:52 +00:00
|
|
|
records = Category.search([], order=[('rec_name', 'ASC')])
|
2022-08-28 20:16:34 +00:00
|
|
|
self.assertEqual(len(records), 15)
|
2022-08-30 20:49:52 +00:00
|
|
|
|
2022-08-28 20:16:34 +00:00
|
|
|
self.assertEqual(records[0].rec_name, 'Fernsehen')
|
2022-08-30 20:49:52 +00:00
|
|
|
self.assertEqual(records[1].rec_name, 'Fernsehen/GEZ')
|
|
|
|
self.assertEqual(records[2].rec_name, 'Fernsehen/TV-Company')
|
|
|
|
self.assertEqual(records[3].rec_name, 'Gehalt')
|
|
|
|
self.assertEqual(records[4].rec_name, 'Gehalt/Zulagen')
|
|
|
|
self.assertEqual(records[5].rec_name, 'Lebensmittel')
|
|
|
|
self.assertEqual(records[6].rec_name, 'Telefon')
|
|
|
|
self.assertEqual(records[7].rec_name, 'Telefon/Telco1-Tablett')
|
|
|
|
self.assertEqual(records[8].rec_name, 'Telefon/Telco2-Handy')
|
|
|
|
self.assertEqual(records[9].rec_name, 'Telefon/Telco3')
|
|
|
|
self.assertEqual(records[10].rec_name, 'Telekommunikation')
|
|
|
|
self.assertEqual(records[11].rec_name, 'Telekommunikation/Fernsehen')
|
|
|
|
self.assertEqual(records[12].rec_name, 'Telekommunikation/Online-Dienste')
|
|
|
|
self.assertEqual(records[13].rec_name, 'Telekommunikation/Telefon')
|
|
|
|
self.assertEqual(records[14].rec_name, 'Telekommunikation/Telefon/Test1')
|
2022-08-28 20:16:34 +00:00
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_category_create_by_qif_existing_categories(self):
|
|
|
|
""" create categories by import a qif-file,
|
|
|
|
some categories exists already
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Category = pool.get('cashbook.category')
|
|
|
|
|
|
|
|
company = self.prep_company()
|
|
|
|
with Transaction().set_context({
|
|
|
|
'company': company.id,
|
|
|
|
}):
|
|
|
|
cat1, = Category.create([{
|
|
|
|
'name': 'Telekommunikation',
|
|
|
|
'cattype': 'out',
|
|
|
|
'childs': [('create', [{
|
|
|
|
'cattype': 'out',
|
|
|
|
'name': 'Telefon',
|
|
|
|
}])],
|
|
|
|
}])
|
|
|
|
|
|
|
|
records = Category.search([])
|
|
|
|
self.assertEqual(len(records), 2)
|
2022-08-30 20:49:52 +00:00
|
|
|
self.assertEqual(records[0].rec_name, 'Telekommunikation')
|
|
|
|
self.assertEqual(records[1].rec_name, 'Telekommunikation/Telefon')
|
2022-08-28 20:16:34 +00:00
|
|
|
|
|
|
|
records1 = Category.create_from_qif(qif_types)
|
|
|
|
|
2022-08-30 20:49:52 +00:00
|
|
|
records = Category.search([], order=[('rec_name', 'ASC')])
|
2022-08-28 20:16:34 +00:00
|
|
|
self.assertEqual(len(records), 15)
|
|
|
|
|
2022-08-30 20:49:52 +00:00
|
|
|
self.assertEqual(records[0].rec_name, 'Fernsehen')
|
|
|
|
self.assertEqual(records[1].rec_name, 'Fernsehen/GEZ')
|
|
|
|
self.assertEqual(records[2].rec_name, 'Fernsehen/TV-Company')
|
|
|
|
self.assertEqual(records[3].rec_name, 'Gehalt')
|
|
|
|
self.assertEqual(records[4].rec_name, 'Gehalt/Zulagen')
|
|
|
|
self.assertEqual(records[5].rec_name, 'Lebensmittel')
|
|
|
|
self.assertEqual(records[6].rec_name, 'Telefon')
|
|
|
|
self.assertEqual(records[7].rec_name, 'Telefon/Telco1-Tablett')
|
|
|
|
self.assertEqual(records[8].rec_name, 'Telefon/Telco2-Handy')
|
|
|
|
self.assertEqual(records[9].rec_name, 'Telefon/Telco3')
|
|
|
|
self.assertEqual(records[10].rec_name, 'Telekommunikation')
|
|
|
|
self.assertEqual(records[11].rec_name, 'Telekommunikation/Fernsehen')
|
|
|
|
self.assertEqual(records[12].rec_name, 'Telekommunikation/Online-Dienste')
|
|
|
|
self.assertEqual(records[13].rec_name, 'Telekommunikation/Telefon')
|
|
|
|
self.assertEqual(records[14].rec_name, 'Telekommunikation/Telefon/Test1')
|
2022-08-28 20:16:34 +00:00
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_qiftool_split_types(self):
|
|
|
|
""" split file-content by types
|
|
|
|
"""
|
|
|
|
QifTool = Pool().get('cashbook_dataexchange.qiftool')
|
|
|
|
|
|
|
|
result = QifTool.split_by_type(qif_types)
|
|
|
|
self.assertEqual(len(result.keys()), 2)
|
|
|
|
self.assertEqual(result['Cat'], 'NGehalt\nI\n^\nNGehalt:Zulagen\n'+
|
|
|
|
'I\n^\nNTelekommunikation\nE\n^\nNTelekommunikation:Online-Dienste\n'+
|
|
|
|
'E\n^\nNTelekommunikation:Telefon\nE\n^\nNTelekommunikation:Telefon:Test1\n'+
|
|
|
|
'E\n^\nNTelefon:Telco1-Tablett\n'+
|
|
|
|
'E\n^\nNTelefon:Telco2-Handy\nE\n^\nNTelefon:Telco3\nE\n^\n'+
|
|
|
|
'NTelekommunikation:Fernsehen\nE\n^\nNFernsehen:TV-Company\nE\n'+
|
|
|
|
'^\nNFernsehen:GEZ\nE\n^\nNLebensmittel\nE\n^')
|
|
|
|
self.assertEqual(result['Bank'], 'D04.12.2013\nT7,12\nCX\nPOpening Balance\n'+
|
|
|
|
'L[Bargeld]\n^\nD05.12.2013\nCX\nM05.12/06.42UHR TT TELTOW\nT290,00\n'+
|
|
|
|
'PGA NR00002168 BLZ10000000 0\nL[S-Giro]\n^\nD05.12.2013\nCX\nMsome food\n'+
|
|
|
|
'T-56,37\nPFoodshop Zehlendorf\nLLebensmittel\n^\n')
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_qiftool_read_categories(self):
|
|
|
|
""" read category-data from text
|
|
|
|
"""
|
|
|
|
QifTool = Pool().get('cashbook_dataexchange.qiftool')
|
|
|
|
|
|
|
|
result = QifTool.qif_read_categories('NGehalt\nI\n^\nNGehalt:Zulagen\nI\n^'+
|
|
|
|
'NTelekommunikation\nE\n^\nNTelekommunikation:Online-Dienste\nE\n^')
|
|
|
|
self.assertEqual(result, {
|
|
|
|
'in': {
|
|
|
|
'Gehalt': {
|
|
|
|
'type': 'in',
|
|
|
|
'childs': {
|
|
|
|
'Zulagen': {
|
|
|
|
'type': 'in',
|
|
|
|
'childs': {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'out': {
|
|
|
|
'Telekommunikation': {
|
|
|
|
'type': 'out',
|
|
|
|
'childs': {
|
|
|
|
'Online-Dienste': {
|
|
|
|
'type': 'out',
|
|
|
|
'childs': {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
# end CategoryTestCase
|