diff --git a/book.py b/book.py
index 261cb64..56c728b 100644
--- a/book.py
+++ b/book.py
@@ -37,10 +37,10 @@ class Book(metaclass=PoolMeta):
if not 'Bank' in qif_content.keys():
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'])
)
- if msg_list == []:
+ if fail_cnt == 0:
Book2.write(*[
[book],
{
diff --git a/category.py b/category.py
index d347f34..0f08960 100644
--- a/category.py
+++ b/category.py
@@ -33,46 +33,12 @@ class Category(metaclass=PoolMeta):
QifTool = pool.get('cashbook_dataexchange.qiftool')
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)
if not 'Cat' in type_data.keys():
return None
- cat_tree = QifTool.qif_read_categories(type_data['Cat'])
- to_create = []
- for typ1 in ['in', 'out']:
- to_create.extend(get_create(typ1, cat_tree[typ1], None, True))
+ to_create = QifTool.convert_categories_to_create(
+ QifTool.qif_read_categories(type_data['Cat']))
return Category2.create(to_create)
# end Category
diff --git a/locale/de.po b/locale/de.po
index 023f10b..5ba30ee 100644
--- a/locale/de.po
+++ b/locale/de.po
@@ -18,31 +18,39 @@ msgctxt "model:ir.message,text:msg_wiz_parties_found"
msgid "The following %(numparties)s parties are now imported:"
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."
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."
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."
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'"
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."
msgstr "Scheck-Nr:"
-msgctxt "model:ir.message,name:mds_import_address"
+msgctxt "model:ir.message,text:mds_import_address"
msgid "Address"
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:"
msgstr "Beim Einlesen der QIF-Datei gab es folgende Probleme:"
diff --git a/locale/en.po b/locale/en.po
index 1bc2211..455bf50 100644
--- a/locale/en.po
+++ b/locale/en.po
@@ -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"
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."
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."
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."
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'"
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."
msgstr "Cheque No."
-msgctxt "model:ir.message,name:mds_import_address"
+msgctxt "model:ir.message,text:mds_import_address"
msgid "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:"
msgstr "When reading the QIF file, there were the following problems:"
diff --git a/message.xml b/message.xml
index 772adaa..265ca49 100644
--- a/message.xml
+++ b/message.xml
@@ -26,6 +26,12 @@ full copyright notices and license terms. -->
The category '%(catname)s' (Type: %(cattype)s) was not found.
+
+ The party '%(pname)s' was not found.
+
+
+ For the party '%(pname)s' of the import, several parties were found in the system. Use: '%(pname2)s'
+
For the category '%(catname1)s' (type: '%(cattype)s') of the import, several categories were found in the system. Use: '%(catname2)s'
diff --git a/qif_import_wiz.py b/qif_import_wiz.py
index 5b985a3..352ceb3 100644
--- a/qif_import_wiz.py
+++ b/qif_import_wiz.py
@@ -110,6 +110,7 @@ class ImportQifWizard(Wizard):
"""
pool = Pool()
QifTool = pool.get('cashbook_dataexchange.qiftool')
+ Category = pool.get('cashbook.category')
model = Transaction().context.get('active_model', '')
file_content = None
@@ -118,34 +119,52 @@ class ImportQifWizard(Wizard):
self.showinfo.allowimport = False
if model == 'cashbook.category':
- def get_catlist(catlist, parent_name=None):
+ def get_catlist(record, cattype, parent_name=None):
""" generate list of categories
"""
names = []
- for name1 in catlist.keys():
- name_lst = []
- if parent_name:
- name_lst.append(parent_name)
- name_lst.append(name1)
- current_name = '/'.join(name_lst)
- names.append(current_name)
- names.extend(get_catlist(catlist[name1]['childs'], current_name))
+
+ if record['cattype'] != cattype:
+ return []
+
+ if 'parent' in record.keys():
+ parent_name = Category(record['parent']).rec_name
+
+ name_lst = []
+ if parent_name:
+ name_lst.append(parent_name)
+ name_lst.append(record['name'])
+ current_name = '/'.join(name_lst)
+ names.append(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
# read file content, extract categories
qif_content = QifTool.split_by_type(file_content)
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(
'cashbook_dataexchange.msg_wiz_categories_found',
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]
)
)
- self.showinfo.allowimport = True
+ if len(to_create) > 0:
+ self.showinfo.allowimport = True
else :
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_categories')
elif model == 'party.party':
@@ -164,36 +183,41 @@ class ImportQifWizard(Wizard):
else :
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_bank')
elif model == 'cashbook.book':
+ info_lst = []
# read file content, extract categories
qif_content = QifTool.split_by_type(file_content)
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'])
)
if len(msg_list) > 0:
+ info_lst.append(gettext('cashbook_dataexchange.msg_wiz_transactions_error'))
+ info_lst.append('')
+
short_lst = []
for x in msg_list:
if x not in short_lst:
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([
x['amount'] \
if x['bookingtype'] in ['in', 'spin'] else x['amount'].copy_sign(Decimal('-1.0')) \
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',
quantity = len(to_create),
balance = Report.format_currency(balance, None, self.start.book.currency),
- )
+ ))
self.showinfo.allowimport = True
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'
diff --git a/qiftool.py b/qiftool.py
index 8a498ef..a3c11e8 100644
--- a/qiftool.py
+++ b/qiftool.py
@@ -119,6 +119,32 @@ class QifTool(Model):
result.append(booking)
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
def get_category_by_name(cls, catname, cattype):
""" find category
@@ -149,6 +175,48 @@ class QifTool(Model):
cat_id = categories[0].id
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
def convert_parties_to_create(cls, transactions):
""" extract party from transaction, check if exist,
@@ -184,6 +252,7 @@ class QifTool(Model):
"""
to_create = []
msg_list = []
+ fail_cnt = 0
for transaction in transactions:
line = {x:transaction[x] for x in [
'date', 'amount', 'description', 'state',
@@ -202,6 +271,16 @@ class QifTool(Model):
line['bookingtype'] = 'out'
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'
cat_name = transaction.get('category', transaction.get('account', None))
cat_type = 'in' if line['bookingtype'] in ['in', 'spin'] else 'out'
@@ -246,7 +325,7 @@ class QifTool(Model):
line['state'] = 'edit'
to_create.append(line)
- return (to_create, msg_list)
+ return (to_create, msg_list, fail_cnt)
@classmethod
def qif_read_categories(cls, catdata):
diff --git a/tests/__init__.py b/tests/__init__.py
index 19ff9ad..1ee073c 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -5,12 +5,16 @@ import trytond.tests.test_tryton
import unittest
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']
class CashbookExchangeTestCase(\
CategoryTestCase,\
+ PartyTestCase,\
+ TransactionTestCase,\
):
'Test cashbook exchange module'
module = 'cashbook_dataexchange'
diff --git a/tests/test_category.py b/tests/test_category.py
index 7cb1b65..206f3b1 100644
--- a/tests/test_category.py
+++ b/tests/test_category.py
@@ -14,7 +14,7 @@ from .qifdata import qif_category, qif_types
class CategoryTestCase(CashbookTestCase):
'Test cashbook categoy module'
- module = 'CashbookExchangeTestCase'
+ module = 'cashbook_dataexchange'
@with_transaction()
def test_wiz_import_category(self):
@@ -247,6 +247,7 @@ I
pool = Pool()
QifTool = pool.get('cashbook_dataexchange.qiftool')
Category = pool.get('cashbook.category')
+ Party = pool.get('party.party')
Book = pool.get('cashbook.book')
company = self.prep_company()
@@ -266,7 +267,21 @@ I
self.assertEqual(book.name, 'Cash Book')
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',
'cattype': 'out',
'company': company.id,
@@ -297,48 +312,52 @@ I
'SLebensmittel\nELebensmittel\n$-49,36\nSKosmetik\nEKlopapier\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(to_create, [{
'date': date(2013, 12, 4),
'amount': Decimal('7.12'),
'state': 'check',
'bookingtype': 'in',
- 'category': 74,
+ 'party': parties[0].id,
+ 'category': categories[4].id,
}, {
'date': date(2013, 12, 5),
'amount': Decimal('290.00'),
'description': '05.12/06.42UHR TT TELTOW',
'state': 'check',
'bookingtype': 'in',
- 'category': 73,
+ 'party': parties[1].id,
+ 'category': categories[3].id,
}, {
'date': date(2013, 12, 5),
'amount': Decimal('56.37'),
'description': 'some food',
'state': 'check',
'bookingtype': 'out',
- 'category': 70,
+ 'party': parties[2].id,
+ 'category': categories[0].id,
}, {
'date': date(2020, 10, 22),
'amount': Decimal('55.84'),
'description': 'Lebensmittel',
'state': 'edit',
'bookingtype': 'spout',
- 'category': 70,
+ 'category': categories[0].id,
+ 'party': parties[3].id,
'splitlines': [
('create', [{
'amount': Decimal('49.36'),
'description': 'Lebensmittel',
- 'category': 70,
+ 'category': categories[0].id,
}, {
'amount': Decimal('2.99'),
'description': 'Klopapier',
- 'category': 72,
+ 'category': categories[2].id,
}, {
'amount': Decimal('3.49'),
'description': 'Sagrotan',
- 'category': 71,
+ 'category': categories[1].id,
}],
)],
}])
diff --git a/tests/test_party.py b/tests/test_party.py
new file mode 100644
index 0000000..a315e7b
--- /dev/null
+++ b/tests/test_party.py
@@ -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
diff --git a/tests/test_transaction.py b/tests/test_transaction.py
new file mode 100644
index 0000000..b400b73
--- /dev/null
+++ b/tests/test_transaction.py
@@ -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