kategorie: erstellt K. aufs qif-datei, wizard begonnen

This commit is contained in:
Frederik Jaeckel 2022-08-28 22:16:34 +02:00
parent 73985fd095
commit 6a6d9bc5d7
13 changed files with 856 additions and 1 deletions

23
tests/__init__.py Normal file
View file

@ -0,0 +1,23 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import trytond.tests.test_tryton
import unittest
from trytond.modules.cashbook_dataexchange.tests.test_category import CategoryTestCase
__all__ = ['suite']
class CashbookExchangeTestCase(\
CategoryTestCase,\
):
'Test cashbook exchange module'
module = 'cashbook_dataexchange'
# end CashbookExchangeTestCase
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookExchangeTestCase))
return suite

386
tests/qifdata.py Normal file
View file

@ -0,0 +1,386 @@
# -*- 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.
qif_types = """
!Type:Cat
NGehalt
I
^
NGehalt:Zulagen
I
^
NTelekommunikation
E
^
NTelekommunikation:Online-Dienste
E
^
NTelekommunikation:Telefon
E
^
NTelekommunikation:Telefon:Test1
E
^
NTelefon:Telco1-Tablett
E
^
NTelefon:Telco2-Handy
E
^
NTelefon:Telco3
E
^
NTelekommunikation:Fernsehen
E
^
NFernsehen:TV-Company
E
^
NFernsehen:GEZ
E
^
NLebensmittel
E
^
!Type:Bank
D04.12.2013
T7,12
CX
POpening Balance
L[Bargeld]
^
D05.12.2013
CX
M05.12/06.42UHR TT TELTOW
T290,00
PGA NR00002168 BLZ10000000 0
L[S-Giro]
^
D05.12.2013
CX
Msome food
T-56,37
PFoodshop Zehlendorf
LLebensmittel
^
"""
qif_category = """!Type:Cat
NGehalt
I
^
NGehalt:Zulagen
I
^
NGehalt:Gehalt
I
^
NSonstiges
I
^
NSonstiges:Prämie
I
^
NSonstiges:Auslagen
I
^
NSonstiges:Gebühren
I
^
NZinsen
I
^
NZinsen:Girokonto
I
^
NZinsen:Sparkonto
I
^
NZinsen:Sonstige
I
^
NGeschenke
I
^
NDividende
I
^
NVerkauf
I
^
NSteuern
I
^
NSteuern:Kapitalertragssteuer
I
^
NTelekommunikation
E
^
NTelekommunikation:Online-Dienste
E
^
NTelekommunikation:Telefon
E
^
NTelefon:Telco1-Tablett
E
^
NTelefon:Telco2-Handy
E
^
NTelefon:Telco3
E
^
NTelekommunikation:Fernsehen
E
^
NFernsehen:TV-Company
E
^
NFernsehen:GEZ
E
^
NLebensmittel
E
^
NVersicherungen
E
^
NVersicherungen:Krankenversicherung
E
^
NVersicherungen:Haftpflicht
E
^
NVersicherungen:Haushalt
E
^
NVersicherungen:KFZ
E
^
NHobbies
E
^
NHobbies:Werkzeug
E
^
NHobbies:Sport
E
^
NHobbies:Fahrrad
E
^
NHobbies:Foto
E
^
NComputer
E
^
NComputer:Software
E
^
NComputer:Hardware
E
^
NGeschenke
E
^
NFahrtkosten
E
^
NFahrtkosten:Fahrkarten
E
^
NFahrtkosten:Fahrrad
E
^
NFahrtkosten:Parken
E
^
NFahrtkosten:Tanken
E
^
NFahrtkosten:Maut
E
^
NFahrtkosten:Verwarngeld
E
^
NFahrtkosten:Auto
E
^
NWohnen
E
^
NWohnen:Miete
E
^
NWohnen:Nebenkosten
E
^
NNebenkosten:Strom
E
^
NNebenkosten:Abfall
E
^
NNebenkosten:Gas
E
^
NNebenkosten:Wasser
E
^
NWohnen:Garten
E
^
NWohnen:Garage
E
^
NSteuern
E
^
NSteuern:Sozialabgaben
E
^
NSteuern:Solidarzuschlag
E
^
NSteuern:Pflegeversicherung
E
^
NSteuern:Einkommenssteuer
E
^
NSteuern:Rentenversicherung
E
^
NSteuern:Sonstige
E
^
NSteuern:KFZ-Steuer
E
^
NMedikamente
E
^
NKleidung
E
^
NSonstiges
E
^
NSonstiges:Bankgebühren
E
^
NSonstiges:Sonstiges
E
^
NSonstiges:Versandkosten
E
^
NSonstiges:Sehhilfe
E
^
NSonstiges:Gebühr
E
^
NSonstiges:Auslage
E
^
NSonstiges:Gutschein
E
^
NSpenden
E
^
NUnterhaltung
E
^
NUnterhaltung:Musik, Kino
E
^
NUnterhaltung:Reisen
E
^
NUnterhaltung:Ausgehen
E
^
NUnterhaltung:Sport
E
^
NUnterhaltung:Urlaub
E
^
NUnterhaltung:Video
E
^
NUnterhaltung:Museum
E
^
NUnterhaltung:Spiele
E
^
NBüroartikel
E
^
NAbonnements
E
^
NZeitungen
E
^
NZeitungen:Newspaper1
E
^
NZeitungen:Newspaper2
E
^
NZeitungen:Newspaper3
E
^
NBücher
E
^
NKosmetik
E
^
NRentenfonds
E
^
NEinrichtung
E
^
NEinrichtung:Technik
E
^
NEinrichtung:Möbel
E
^
NEinrichtung:Haushalt
E
^
NZinsen
E
^
NZinsen:Sollzinsen
E
^
NHaushaltschemie
E
^
NGesundheit
E
^
NGesundheit:Zahnarzt
E
^
NLuxusgüter
E
^
NLuxusgüter:Uhr
E
^
"""

150
tests/test_category.py Normal file
View file

@ -0,0 +1,150 @@
# -*- 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'
@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)
records = Category.search([], order=[('name', 'ASC')])
self.assertEqual(len(records), 15)
self.assertEqual(records[0].rec_name, 'Fernsehen')
self.assertEqual(records[1].rec_name, 'Telekommunikation/Fernsehen')
self.assertEqual(records[2].rec_name, 'Gehalt')
self.assertEqual(records[3].rec_name, 'Fernsehen/GEZ')
self.assertEqual(records[4].rec_name, 'Lebensmittel')
self.assertEqual(records[5].rec_name, 'Telekommunikation/Online-Dienste')
self.assertEqual(records[6].rec_name, 'Telefon/Telco1-Tablett')
self.assertEqual(records[7].rec_name, 'Telefon/Telco2-Handy')
self.assertEqual(records[8].rec_name, 'Telefon/Telco3')
self.assertEqual(records[9].rec_name, 'Telekommunikation/Telefon')
self.assertEqual(records[10].rec_name, 'Telefon')
self.assertEqual(records[11].rec_name, 'Telekommunikation')
self.assertEqual(records[12].rec_name, 'Telekommunikation/Telefon/Test1')
self.assertEqual(records[13].rec_name, 'Fernsehen/TV-Company')
self.assertEqual(records[14].rec_name, 'Gehalt/Zulagen')
@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)
self.assertEqual(records[0].rec_name, 'Telekommunikation/Telefon')
self.assertEqual(records[1].rec_name, 'Telekommunikation')
records1 = Category.create_from_qif(qif_types)
records = Category.search([], order=[('name', 'ASC')])
self.assertEqual(len(records), 15)
for rec in records:
print('-rec:', rec.rec_name)
self.assertEqual(records[0].rec_name, 'Telekommunikation/Fernsehen')
self.assertEqual(records[1].rec_name, 'Fernsehen')
self.assertEqual(records[2].rec_name, 'Gehalt')
self.assertEqual(records[3].rec_name, 'Fernsehen/GEZ')
self.assertEqual(records[4].rec_name, 'Lebensmittel')
self.assertEqual(records[5].rec_name, 'Telekommunikation/Online-Dienste')
self.assertEqual(records[6].rec_name, 'Telefon/Telco1-Tablett')
self.assertEqual(records[7].rec_name, 'Telefon/Telco2-Handy')
self.assertEqual(records[8].rec_name, 'Telefon/Telco3')
self.assertEqual(records[9].rec_name, 'Telefon')
self.assertEqual(records[10].rec_name, 'Telekommunikation/Telefon')
self.assertEqual(records[11].rec_name, 'Telekommunikation')
self.assertEqual(records[12].rec_name, 'Telekommunikation/Telefon/Test1')
self.assertEqual(records[13].rec_name, 'Fernsehen/TV-Company')
self.assertEqual(records[14].rec_name, 'Gehalt/Zulagen')
@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