import: party, transaction

übersetzung korrigiert
This commit is contained in:
Frederik Jaeckel 2022-09-02 14:33:12 +02:00
parent a26e7119eb
commit 78d02a60b7
11 changed files with 383 additions and 86 deletions

View file

@ -37,10 +37,10 @@ class Book(metaclass=PoolMeta):
if not 'Bank' in qif_content.keys(): if not 'Bank' in qif_content.keys():
return None return None
(to_create, msg_list) = QifTool.convert_transactions_to_create( (to_create, msg_list, fail_cnt) = QifTool.convert_transactions_to_create(
QifTool.qif_read_transactions(qif_content['Bank']) QifTool.qif_read_transactions(qif_content['Bank'])
) )
if msg_list == []: if fail_cnt == 0:
Book2.write(*[ Book2.write(*[
[book], [book],
{ {

View file

@ -33,46 +33,12 @@ class Category(metaclass=PoolMeta):
QifTool = pool.get('cashbook_dataexchange.qiftool') QifTool = pool.get('cashbook_dataexchange.qiftool')
Category2 = pool.get('cashbook.category') Category2 = pool.get('cashbook.category')
def get_create(ctype, catdict, parent, do_search):
""" check if category exists, generate create-data
"""
result = []
for catname in catdict.keys():
if do_search == True:
c_lst = Category2.search([
('cattype', '=', ctype),
('name', '=', catname),
('parent', '=', None) if parent is None else ('parent.id', '=', parent.id),
])
else :
c_lst = []
if len(c_lst) == 0:
cat1 = {
'cattype': ctype,
'name': catname,
}
if parent is not None:
cat1['parent'] = parent.id
if len(catdict[catname]['childs']) > 0:
childs = get_create(ctype, catdict[catname]['childs'], None, False)
if len(childs) > 0:
cat1['childs'] = [('create', childs)]
result.append(cat1)
else :
if len(catdict[catname]['childs']) > 0:
result.extend(get_create(ctype, catdict[catname]['childs'], c_lst[0], True))
return result
type_data = QifTool.split_by_type(qifdata) type_data = QifTool.split_by_type(qifdata)
if not 'Cat' in type_data.keys(): if not 'Cat' in type_data.keys():
return None return None
cat_tree = QifTool.qif_read_categories(type_data['Cat']) to_create = QifTool.convert_categories_to_create(
to_create = [] QifTool.qif_read_categories(type_data['Cat']))
for typ1 in ['in', 'out']:
to_create.extend(get_create(typ1, cat_tree[typ1], None, True))
return Category2.create(to_create) return Category2.create(to_create)
# end Category # end Category

View file

@ -18,31 +18,39 @@ msgctxt "model:ir.message,text:msg_wiz_parties_found"
msgid "The following %(numparties)s parties are now imported:" msgid "The following %(numparties)s parties are now imported:"
msgstr "Die folgenden %(numparties)s Parteien werden nun importiert:" msgstr "Die folgenden %(numparties)s Parteien werden nun importiert:"
msgctxt "model:ir.message,name:msg_wiz_no_categories" msgctxt "model:ir.message,text:msg_wiz_no_categories"
msgid "No categories were found in the file." msgid "No categories were found in the file."
msgstr "In der Datei wurden keine Kategorien gefunden." msgstr "In der Datei wurden keine Kategorien gefunden."
msgctxt "model:ir.message,name:msg_wiz_no_bank" msgctxt "model:ir.message,text:msg_wiz_no_bank"
msgid "No transactions were found in the file." msgid "No transactions were found in the file."
msgstr "In der Datei wurden keine Transaktionen gefunden." msgstr "In der Datei wurden keine Transaktionen gefunden."
msgctxt "model:ir.message,name:mds_import_category_notfound" msgctxt "model:ir.message,text:mds_import_category_notfound"
msgid "The category '%(catname)s' (Type: %(cattype)s) was not found." msgid "The category '%(catname)s' (Type: %(cattype)s) was not found."
msgstr "Die Kategorie '%(catname)s' (Typ: %(cattype)s) wurde nicht gefunden." msgstr "Die Kategorie '%(catname)s' (Typ: %(cattype)s) wurde nicht gefunden."
msgctxt "model:ir.message,name:mds_import_many_categories_found" msgctxt "model:ir.message,text:mds_import_party_notfound"
msgid "The party '%(pname)s' was not found."
msgstr "Die Partei '%(pname)s' wurde nicht gefunden."
msgctxt "model:ir.message,text:mds_import_many_parties_found"
msgid "For the party '%(pname)s' of the import, several parties were found in the system. Use: '%(pname2)s'"
msgstr "Für die Partei '%(pname)s' des Imports wurden mehrere Parteien im System gefunden. Verwende: '%(pname2)s'"
msgctxt "model:ir.message,text:mds_import_many_categories_found"
msgid "For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'" msgid "For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'"
msgstr "Für die Kategorie '%(catname1)s' (Typ: '%(cattype)s') des Imports wurden mehrere Kategorien im System gefunden. Verwende: '%(catname2)s'" msgstr "Für die Kategorie '%(catname1)s' (Typ: '%(cattype)s') des Imports wurden mehrere Kategorien im System gefunden. Verwende: '%(catname2)s'"
msgctxt "model:ir.message,name:mds_import_checknumber" msgctxt "model:ir.message,text:mds_import_checknumber"
msgid "Cheque No." msgid "Cheque No."
msgstr "Scheck-Nr:" msgstr "Scheck-Nr:"
msgctxt "model:ir.message,name:mds_import_address" msgctxt "model:ir.message,text:mds_import_address"
msgid "Address" msgid "Address"
msgstr "Adresse" msgstr "Adresse"
msgctxt "model:ir.message,name:msg_wiz_transactions_error" msgctxt "model:ir.message,text:msg_wiz_transactions_error"
msgid "When reading the QIF file, there were the following problems:" msgid "When reading the QIF file, there were the following problems:"
msgstr "Beim Einlesen der QIF-Datei gab es folgende Probleme:" msgstr "Beim Einlesen der QIF-Datei gab es folgende Probleme:"

View file

@ -10,31 +10,43 @@ msgctxt "model:ir.message,text:msg_wiz_transactions_found"
msgid "The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s" msgid "The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s"
msgstr "The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s" msgstr "The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s"
msgctxt "model:ir.message,name:msg_wiz_no_categories" msgctxt "model:ir.message,text:msg_wiz_parties_found"
msgid "The following %(numparties)s parties are now imported:"
msgstr "The following %(numparties)s parties are now imported:"
msgctxt "model:ir.message,text:msg_wiz_no_categories"
msgid "No categories were found in the file." msgid "No categories were found in the file."
msgstr "No categories were found in the file." msgstr "No categories were found in the file."
msgctxt "model:ir.message,name:msg_wiz_no_bank" msgctxt "model:ir.message,text:msg_wiz_no_bank"
msgid "No transactions were found in the file." msgid "No transactions were found in the file."
msgstr "No transactions were found in the file." msgstr "No transactions were found in the file."
msgctxt "model:ir.message,name:mds_import_category_notfound" msgctxt "model:ir.message,text:mds_import_category_notfound"
msgid "The category '%(catname)s' (Type: %(cattype)s) was not found." msgid "The category '%(catname)s' (Type: %(cattype)s) was not found."
msgstr "The category '%(catname)s' (Type: %(cattype)s) was not found." msgstr "The category '%(catname)s' (Type: %(cattype)s) was not found."
msgctxt "model:ir.message,name:mds_import_many_categories_found" msgctxt "model:ir.message,text:mds_import_party_notfound"
msgid "The party '%(pname)s' was not found."
msgstr "The party '%(pname)s' was not found."
msgctxt "model:ir.message,text:mds_import_many_parties_found"
msgid "For the party '%(pname)s' of the import, several parties were found in the system. Use: '%(pname2)s'"
msgstr "For the party '%(pname)s' of the import, several parties were found in the system. Use: '%(pname2)s'"
msgctxt "model:ir.message,text:mds_import_many_categories_found"
msgid "For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'" msgid "For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'"
msgstr "For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'" msgstr "For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'"
msgctxt "model:ir.message,name:mds_import_checknumber" msgctxt "model:ir.message,text:mds_import_checknumber"
msgid "Cheque No." msgid "Cheque No."
msgstr "Cheque No." msgstr "Cheque No."
msgctxt "model:ir.message,name:mds_import_address" msgctxt "model:ir.message,text:mds_import_address"
msgid "Address" msgid "Address"
msgstr "Address" msgstr "Address"
msgctxt "model:ir.message,name:msg_wiz_transactions_error" msgctxt "model:ir.message,text:msg_wiz_transactions_error"
msgid "When reading the QIF file, there were the following problems:" msgid "When reading the QIF file, there were the following problems:"
msgstr "When reading the QIF file, there were the following problems:" msgstr "When reading the QIF file, there were the following problems:"

View file

@ -26,6 +26,12 @@ full copyright notices and license terms. -->
<record model="ir.message" id="mds_import_category_notfound"> <record model="ir.message" id="mds_import_category_notfound">
<field name="text">The category '%(catname)s' (Type: %(cattype)s) was not found.</field> <field name="text">The category '%(catname)s' (Type: %(cattype)s) was not found.</field>
</record> </record>
<record model="ir.message" id="mds_import_party_notfound">
<field name="text">The party '%(pname)s' was not found.</field>
</record>
<record model="ir.message" id="mds_import_many_parties_found">
<field name="text">For the party '%(pname)s' of the import, several parties were found in the system. Use: '%(pname2)s'</field>
</record>
<record model="ir.message" id="mds_import_many_categories_found"> <record model="ir.message" id="mds_import_many_categories_found">
<field name="text">For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'</field> <field name="text">For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'</field>
</record> </record>

View file

@ -110,6 +110,7 @@ class ImportQifWizard(Wizard):
""" """
pool = Pool() pool = Pool()
QifTool = pool.get('cashbook_dataexchange.qiftool') QifTool = pool.get('cashbook_dataexchange.qiftool')
Category = pool.get('cashbook.category')
model = Transaction().context.get('active_model', '') model = Transaction().context.get('active_model', '')
file_content = None file_content = None
@ -118,33 +119,51 @@ class ImportQifWizard(Wizard):
self.showinfo.allowimport = False self.showinfo.allowimport = False
if model == 'cashbook.category': if model == 'cashbook.category':
def get_catlist(catlist, parent_name=None): def get_catlist(record, cattype, parent_name=None):
""" generate list of categories """ generate list of categories
""" """
names = [] names = []
for name1 in catlist.keys():
if record['cattype'] != cattype:
return []
if 'parent' in record.keys():
parent_name = Category(record['parent']).rec_name
name_lst = [] name_lst = []
if parent_name: if parent_name:
name_lst.append(parent_name) name_lst.append(parent_name)
name_lst.append(name1) name_lst.append(record['name'])
current_name = '/'.join(name_lst) current_name = '/'.join(name_lst)
names.append(current_name) names.append(current_name)
names.extend(get_catlist(catlist[name1]['childs'], current_name))
if 'childs' in record.keys():
# record['childs']: [('create', [{}, ...]))]
for x in record['childs'][0][1]:
names.extend(get_catlist(x, cattype, current_name))
return names return names
# read file content, extract categories # read file content, extract categories
qif_content = QifTool.split_by_type(file_content) qif_content = QifTool.split_by_type(file_content)
if 'Cat' in qif_content.keys(): if 'Cat' in qif_content.keys():
categories = QifTool.qif_read_categories(qif_content['Cat']) to_create = QifTool.convert_categories_to_create(QifTool.qif_read_categories(qif_content['Cat']))
in_categories = []
out_categories = []
for x in to_create:
in_categories.extend(get_catlist(x, 'in'))
out_categories.extend(get_catlist(x, 'out'))
self.showinfo.info = gettext( self.showinfo.info = gettext(
'cashbook_dataexchange.msg_wiz_categories_found', 'cashbook_dataexchange.msg_wiz_categories_found',
categories = '\n'.join( categories = '\n'.join(
[''] + [''] +
['%s (in)' % x for x in get_catlist(categories['in'], None)]+ ['%s (in)' % x for x in in_categories]+
[''] + [''] +
['%s (out)' % x for x in get_catlist(categories['out'], None)] ['%s (out)' % x for x in out_categories]
) )
) )
if len(to_create) > 0:
self.showinfo.allowimport = True self.showinfo.allowimport = True
else : else :
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_categories') self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_categories')
@ -164,36 +183,41 @@ class ImportQifWizard(Wizard):
else : else :
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_bank') self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_bank')
elif model == 'cashbook.book': elif model == 'cashbook.book':
info_lst = []
# read file content, extract categories # read file content, extract categories
qif_content = QifTool.split_by_type(file_content) qif_content = QifTool.split_by_type(file_content)
if 'Bank' in qif_content.keys(): if 'Bank' in qif_content.keys():
(to_create, msg_list) = QifTool.convert_transactions_to_create( (to_create, msg_list, fail_cnt) = QifTool.convert_transactions_to_create(
QifTool.qif_read_transactions(qif_content['Bank']) QifTool.qif_read_transactions(qif_content['Bank'])
) )
if len(msg_list) > 0: if len(msg_list) > 0:
info_lst.append(gettext('cashbook_dataexchange.msg_wiz_transactions_error'))
info_lst.append('')
short_lst = [] short_lst = []
for x in msg_list: for x in msg_list:
if x not in short_lst: if x not in short_lst:
short_lst.append(x) short_lst.append(x)
info_lst.extend(short_lst)
info_lst.append('')
self.showinfo.info = '%s\n\n%s' % (
gettext('cashbook_dataexchange.msg_wiz_transactions_error'),
'\n'.join(short_lst),
)
else :
# count # count
if fail_cnt == 0:
balance = sum([ balance = sum([
x['amount'] \ x['amount'] \
if x['bookingtype'] in ['in', 'spin'] else x['amount'].copy_sign(Decimal('-1.0')) \ if x['bookingtype'] in ['in', 'spin'] else x['amount'].copy_sign(Decimal('-1.0')) \
for x in to_create]) for x in to_create])
self.showinfo.info = gettext( if len(msg_list) > 0:
msg_list.append('')
info_lst.append(gettext(
'cashbook_dataexchange.msg_wiz_transactions_found', 'cashbook_dataexchange.msg_wiz_transactions_found',
quantity = len(to_create), quantity = len(to_create),
balance = Report.format_currency(balance, None, self.start.book.currency), balance = Report.format_currency(balance, None, self.start.book.currency),
) ))
self.showinfo.allowimport = True self.showinfo.allowimport = True
else : else :
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_bank') info_lst.append(gettext('cashbook_dataexchange.msg_wiz_no_bank'))
self.showinfo.info = '\n'.join(info_lst)
return 'showinfo' return 'showinfo'

View file

@ -119,6 +119,32 @@ class QifTool(Model):
result.append(booking) result.append(booking)
return result return result
@classmethod
def get_party_by_name(cls, partyname):
""" find party
"""
Party = Pool().get('party.party')
party_id = None
msg_txt = None
parties = Party.search([('rec_name', 'ilike', '%%%s%%' % partyname)])
if len(parties) == 0:
msg_txt = gettext(
'cashbook_dataexchange.mds_import_party_notfound',
pname = partyname,
)
elif len(parties) == 1:
party_id = parties[0].id
else :
party_id = parties[0].id
msg_txt = gettext(
'cashbook_dataexchange.mds_import_many_parties_found',
pname = partyname,
pname2 = parties[0].rec_name,
)
return (party_id, msg_txt)
@classmethod @classmethod
def get_category_by_name(cls, catname, cattype): def get_category_by_name(cls, catname, cattype):
""" find category """ find category
@ -149,6 +175,48 @@ class QifTool(Model):
cat_id = categories[0].id cat_id = categories[0].id
return (cat_id, msg_txt) return (cat_id, msg_txt)
@classmethod
def convert_categories_to_create(cls, cat_tree):
""" cat_tree: result from cls.qif_read_categories()
"""
Category = Pool().get('cashbook.category')
def get_create(ctype, catdict, parent, do_search):
""" check if category exists, generate create-data
"""
result = []
for catname in catdict.keys():
if do_search == True:
c_lst = Category.search([
('cattype', '=', ctype),
('name', '=', catname),
('parent', '=', None) if parent is None else ('parent.id', '=', parent.id),
])
else :
c_lst = []
if len(c_lst) == 0:
cat1 = {
'cattype': ctype,
'name': catname,
}
if parent is not None:
cat1['parent'] = parent.id
if len(catdict[catname]['childs']) > 0:
childs = get_create(ctype, catdict[catname]['childs'], None, False)
if len(childs) > 0:
cat1['childs'] = [('create', childs)]
result.append(cat1)
else :
if len(catdict[catname]['childs']) > 0:
result.extend(get_create(ctype, catdict[catname]['childs'], c_lst[0], True))
return result
to_create = []
for typ1 in ['in', 'out']:
to_create.extend(get_create(typ1, cat_tree[typ1], None, True))
return to_create
@classmethod @classmethod
def convert_parties_to_create(cls, transactions): def convert_parties_to_create(cls, transactions):
""" extract party from transaction, check if exist, """ extract party from transaction, check if exist,
@ -184,6 +252,7 @@ class QifTool(Model):
""" """
to_create = [] to_create = []
msg_list = [] msg_list = []
fail_cnt = 0
for transaction in transactions: for transaction in transactions:
line = {x:transaction[x] for x in [ line = {x:transaction[x] for x in [
'date', 'amount', 'description', 'state', 'date', 'amount', 'description', 'state',
@ -202,6 +271,16 @@ class QifTool(Model):
line['bookingtype'] = 'out' line['bookingtype'] = 'out'
line['amount'] = line['amount'].copy_sign(Decimal('1.0')) line['amount'] = line['amount'].copy_sign(Decimal('1.0'))
# party
if 'party' in transaction.keys():
(party_id, msg_txt) = cls.get_party_by_name(transaction['party'])
if party_id is not None:
line['party'] = party_id
else :
fail_cnt += 1
if msg_txt is not None:
msg_list.append(msg_txt)
# store 'account' like 'category' # store 'account' like 'category'
cat_name = transaction.get('category', transaction.get('account', None)) cat_name = transaction.get('category', transaction.get('account', None))
cat_type = 'in' if line['bookingtype'] in ['in', 'spin'] else 'out' cat_type = 'in' if line['bookingtype'] in ['in', 'spin'] else 'out'
@ -246,7 +325,7 @@ class QifTool(Model):
line['state'] = 'edit' line['state'] = 'edit'
to_create.append(line) to_create.append(line)
return (to_create, msg_list) return (to_create, msg_list, fail_cnt)
@classmethod @classmethod
def qif_read_categories(cls, catdata): def qif_read_categories(cls, catdata):

View file

@ -5,12 +5,16 @@ import trytond.tests.test_tryton
import unittest import unittest
from trytond.modules.cashbook_dataexchange.tests.test_category import CategoryTestCase from trytond.modules.cashbook_dataexchange.tests.test_category import CategoryTestCase
from trytond.modules.cashbook_dataexchange.tests.test_party import PartyTestCase
from trytond.modules.cashbook_dataexchange.tests.test_transaction import TransactionTestCase
__all__ = ['suite'] __all__ = ['suite']
class CashbookExchangeTestCase(\ class CashbookExchangeTestCase(\
CategoryTestCase,\ CategoryTestCase,\
PartyTestCase,\
TransactionTestCase,\
): ):
'Test cashbook exchange module' 'Test cashbook exchange module'
module = 'cashbook_dataexchange' module = 'cashbook_dataexchange'

View file

@ -14,7 +14,7 @@ from .qifdata import qif_category, qif_types
class CategoryTestCase(CashbookTestCase): class CategoryTestCase(CashbookTestCase):
'Test cashbook categoy module' 'Test cashbook categoy module'
module = 'CashbookExchangeTestCase' module = 'cashbook_dataexchange'
@with_transaction() @with_transaction()
def test_wiz_import_category(self): def test_wiz_import_category(self):
@ -247,6 +247,7 @@ I
pool = Pool() pool = Pool()
QifTool = pool.get('cashbook_dataexchange.qiftool') QifTool = pool.get('cashbook_dataexchange.qiftool')
Category = pool.get('cashbook.category') Category = pool.get('cashbook.category')
Party = pool.get('party.party')
Book = pool.get('cashbook.book') Book = pool.get('cashbook.book')
company = self.prep_company() company = self.prep_company()
@ -266,7 +267,21 @@ I
self.assertEqual(book.name, 'Cash Book') self.assertEqual(book.name, 'Cash Book')
self.assertEqual(book.btype.rec_name, 'CAS - Cash') self.assertEqual(book.btype.rec_name, 'CAS - Cash')
Category.create([{ parties = Party.create([{
'name': 'Opening Balance',
'addresses': [('create', [{}])],
}, {
'name': 'GA NR00002168 BLZ10000000 0',
'addresses': [('create', [{}])],
}, {
'name': 'Foodshop Zehlendorf',
'addresses': [('create', [{}])],
}, {
'name': 'real,- Teltow',
'addresses': [('create', [{}])],
}])
categories = Category.create([{
'name': 'Lebensmittel', 'name': 'Lebensmittel',
'cattype': 'out', 'cattype': 'out',
'company': company.id, 'company': company.id,
@ -297,48 +312,52 @@ I
'SLebensmittel\nELebensmittel\n$-49,36\nSKosmetik\nEKlopapier\n'+ 'SLebensmittel\nELebensmittel\n$-49,36\nSKosmetik\nEKlopapier\n'+
'$-2,99\nSHaushaltschemie\nESagrotan\n$-3,49\n^\n') '$-2,99\nSHaushaltschemie\nESagrotan\n$-3,49\n^\n')
(to_create, msg_txt) = QifTool.convert_transactions_to_create(tr_list) (to_create, msg_txt, fail_cnt) = QifTool.convert_transactions_to_create(tr_list)
self.assertEqual(msg_txt, []) self.assertEqual(msg_txt, [])
self.assertEqual(to_create, [{ self.assertEqual(to_create, [{
'date': date(2013, 12, 4), 'date': date(2013, 12, 4),
'amount': Decimal('7.12'), 'amount': Decimal('7.12'),
'state': 'check', 'state': 'check',
'bookingtype': 'in', 'bookingtype': 'in',
'category': 74, 'party': parties[0].id,
'category': categories[4].id,
}, { }, {
'date': date(2013, 12, 5), 'date': date(2013, 12, 5),
'amount': Decimal('290.00'), 'amount': Decimal('290.00'),
'description': '05.12/06.42UHR TT TELTOW', 'description': '05.12/06.42UHR TT TELTOW',
'state': 'check', 'state': 'check',
'bookingtype': 'in', 'bookingtype': 'in',
'category': 73, 'party': parties[1].id,
'category': categories[3].id,
}, { }, {
'date': date(2013, 12, 5), 'date': date(2013, 12, 5),
'amount': Decimal('56.37'), 'amount': Decimal('56.37'),
'description': 'some food', 'description': 'some food',
'state': 'check', 'state': 'check',
'bookingtype': 'out', 'bookingtype': 'out',
'category': 70, 'party': parties[2].id,
'category': categories[0].id,
}, { }, {
'date': date(2020, 10, 22), 'date': date(2020, 10, 22),
'amount': Decimal('55.84'), 'amount': Decimal('55.84'),
'description': 'Lebensmittel', 'description': 'Lebensmittel',
'state': 'edit', 'state': 'edit',
'bookingtype': 'spout', 'bookingtype': 'spout',
'category': 70, 'category': categories[0].id,
'party': parties[3].id,
'splitlines': [ 'splitlines': [
('create', [{ ('create', [{
'amount': Decimal('49.36'), 'amount': Decimal('49.36'),
'description': 'Lebensmittel', 'description': 'Lebensmittel',
'category': 70, 'category': categories[0].id,
}, { }, {
'amount': Decimal('2.99'), 'amount': Decimal('2.99'),
'description': 'Klopapier', 'description': 'Klopapier',
'category': 72, 'category': categories[2].id,
}, { }, {
'amount': Decimal('3.49'), 'amount': Decimal('3.49'),
'description': 'Sagrotan', 'description': 'Sagrotan',
'category': 71, 'category': categories[1].id,
}], }],
)], )],
}]) }])

71
tests/test_party.py Normal file
View file

@ -0,0 +1,71 @@
# -*- 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 datetime import date
from decimal import Decimal
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from .qifdata import qif_types
class PartyTestCase(ModuleTestCase):
'Test cashbook party module'
module = 'cashbook_dataexchange'
@with_transaction()
def test_wiz_import_party(self):
""" create parties by run wizard
"""
pool = Pool()
Party = pool.get('party.party')
ImportWiz = pool.get('cashbook_dataexchange.qif_imp_wiz', type='wizard')
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
'active_model': 'party.party',
}):
(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 3 parties are now imported:\n
Opening Balance
GA NR00002168 BLZ10000000 0
Foodshop Zehlendorf""")
r1 = {'company': company.id}
result = ImportWiz.execute(sess_id, {'showinfo': r1}, 'importf')
self.assertEqual(list(result.keys()), [])
ImportWiz.delete(sess_id)
records = Party.search([], order=[('name', 'ASC')])
self.assertEqual(len(records), 4)
self.assertEqual(records[0].rec_name, 'Foodshop Zehlendorf')
self.assertEqual(records[1].rec_name, 'GA NR00002168 BLZ10000000 0')
self.assertEqual(records[2].rec_name, 'm-ds')
self.assertEqual(records[3].rec_name, 'Opening Balance')
# end PartyTestCase

108
tests/test_transaction.py Normal file
View file

@ -0,0 +1,108 @@
# -*- 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 datetime import date
from decimal import Decimal
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.transaction import Transaction
from .qifdata import qif_types
class TransactionTestCase(ModuleTestCase):
'Test cashbook transaction module'
module = 'cashbook_dataexchange'
@with_transaction()
def test_wiz_import_transactions(self):
""" create transactions by run wizard
"""
pool = Pool()
Party = pool.get('party.party')
Category = pool.get('cashbook.category')
Book = pool.get('cashbook.book')
ImportWiz = pool.get('cashbook_dataexchange.qif_imp_wiz', type='wizard')
company = self.prep_company()
with Transaction().set_context({
'company': company.id,
'active_model': 'cashbook.book',
}):
types = self.prep_type()
book, = Book.create([{
'name': 'Cash Book',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2010, 1, 1),
'start_balance': Decimal('0.0'),
}])
Party.create([{
'name': 'GA NR00002168 BLZ10000000 0',
'addresses':[('create', [{}])],
}, {
'name': 'Foodshop Zehlendorf',
'addresses':[('create', [{}])],
}, {
'name': 'Opening Balance',
'addresses':[('create', [{}])],
}])
Category.create([{
'name':'Bargeld',
'cattype': 'in',
}, {
'name': 'S-Giro',
'cattype': 'in',
}, {
'name': 'Lebensmittel',
'cattype': 'out',
}])
(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
r1['book'] = book.id
w_obj.start.file_ = r1['file_']
w_obj.start.company = company.id
w_obj.start.book = book.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 transactionen are now imported:
Balance: usd240.75
Number of transactions: 3""")
r1 = {
'company': company.id,
'book': book.id,
}
result = ImportWiz.execute(sess_id, {'showinfo': r1}, 'importf')
self.assertEqual(list(result.keys()), [])
ImportWiz.delete(sess_id)
self.assertEqual(len(book.lines), 3)
self.assertEqual(book.lines[0].rec_name, '12/04/2013|Rev|7.12 usd|- [Bargeld]')
self.assertEqual(book.lines[1].rec_name, '12/05/2013|Rev|290.00 usd|05.12/06.42UHR TT TELTOW [S-Giro]')
self.assertEqual(book.lines[2].rec_name, '12/05/2013|Exp|-56.37 usd|some food [Lebensmittel]')
# end PartyTestCase