# -*- 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: Credit: usd297.12 Debit: usd56.37 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]') self.assertEqual(Book.export_as_qif(book), """!Type:Bank D12/04/2013 T7.12 CX POpening Balance LBargeld ^ D12/05/2013 T290.00 CX PGA NR00002168 BLZ10000000 0 LS-Giro M05.12/06.42UHR TT TELTOW ^ D12/05/2013 T-56.37 CX PFoodshop Zehlendorf LLebensmittel Msome food ^""") # end PartyTestCase