149 lines
4.9 KiB
Python
149 lines
4.9 KiB
Python
# -*- 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()
|
|
books = 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'),
|
|
}, {
|
|
'name': 'S-Giro',
|
|
'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'),
|
|
}, {
|
|
'name': 'Bargeld',
|
|
'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': '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'] = books[0].id
|
|
w_obj.start.file_ = r1['file_']
|
|
w_obj.start.company = company.id
|
|
w_obj.start.book = books[0].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:
|
|
Credit: usd7.12
|
|
Debit: usd83.92
|
|
Balance: -usd76.80
|
|
Number of transactions: 4""")
|
|
|
|
r1 = {
|
|
'company': company.id,
|
|
'book': books[0].id,
|
|
}
|
|
result = ImportWiz.execute(sess_id, {'showinfo': r1}, 'importf')
|
|
self.assertEqual(list(result.keys()), [])
|
|
|
|
ImportWiz.delete(sess_id)
|
|
|
|
self.assertEqual(len(books[0].lines), 4)
|
|
|
|
self.assertEqual(books[0].lines[0].rec_name, '12/05/2013|Exp|-56.37 usd|some food [Lebensmittel]')
|
|
self.assertEqual(books[0].lines[1].rec_name, '12/06/2013|Exp|1.45 usd|return of bottles [Lebensmittel]')
|
|
self.assertEqual(books[0].lines[2].rec_name, '12/04/2013|from|7.12 usd|Opening Balance [Bargeld | 0.00 usd | Open]')
|
|
self.assertEqual(books[0].lines[3].rec_name, '12/05/2013|to|-29.00 usd|GA NR00002168 BLZ10000000 0; 05.12/06.42 [S-Giro | 0.00 usd | Open]')
|
|
|
|
self.assertEqual(Book.export_as_qif(books[0]), """!Type:Bank
|
|
D12/05/2013
|
|
T-56.37
|
|
CX
|
|
PFoodshop Zehlendorf
|
|
LLebensmittel
|
|
Msome food
|
|
^
|
|
D12/06/2013
|
|
T1.45
|
|
CX
|
|
PFoodshop Zehlendorf
|
|
LLebensmittel
|
|
Mreturn of bottles
|
|
^
|
|
D12/04/2013
|
|
T7.12
|
|
C*
|
|
L[Bargeld]
|
|
MOpening Balance
|
|
^
|
|
D12/05/2013
|
|
T-29.00
|
|
C*
|
|
L[S-Giro]
|
|
MGA NR00002168 BLZ10000000 0; 05.12/06.42UHR TT TELTOW
|
|
^""")
|
|
|
|
# end PartyTestCase
|