Browse Source
[FIX] Restructure and expand tests. Fix some bugs.
[FIX] Restructure and expand tests. Fix some bugs.
There is now a common class to test import of statements and their transactions. Fixes: - Field in regular expression for mt940 rabo parser was to short for bank-account. - Wrong name used for reference attribute in mt940 rabo parser; - Attribute transferred_amount should not have been renamed amount in BankTransaction.pull/15/head
Ronald Portier (Therp BV)
10 years ago
9 changed files with 208 additions and 152 deletions
-
22account_bank_statement_import/account_bank_statement_import.py
-
2account_bank_statement_import/tests/__init__.py
-
132account_bank_statement_import/tests/test_import_file.py
-
8bank_statement_parse/parserlib.py
-
57bank_statement_parse_camt/tests/test_import_bank_statement.py
-
66bank_statement_parse_nl_ing_mt940/tests/test_import_bank_statement.py
-
3bank_statement_parse_nl_rabo_mt940/account_bank_statement_import.py
-
4bank_statement_parse_nl_rabo_mt940/mt940.py
-
66bank_statement_parse_nl_rabo_mt940/tests/test_import_bank_statement.py
@ -1,3 +1,5 @@ |
|||||
# -*- encoding: utf-8 -*- |
# -*- encoding: utf-8 -*- |
||||
|
"""Define tests to be run.""" |
||||
from . import test_res_partner_bank |
from . import test_res_partner_bank |
||||
from . import test_import_bank_statement |
from . import test_import_bank_statement |
||||
|
from .test_import_file import TestStatementFile |
@ -0,0 +1,132 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
"""Provide common base for bank statement import tests.""" |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# All other contributions are (C) by their respective contributors |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
import logging |
||||
|
|
||||
|
from openerp.tests.common import TransactionCase |
||||
|
from openerp.modules.module import get_module_resource |
||||
|
|
||||
|
|
||||
|
_LOGGER = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class TestStatementFile(TransactionCase): |
||||
|
"""Check wether statements with transactions correctly imported. |
||||
|
|
||||
|
No actual tests are done in this class, implementations are in |
||||
|
subclasses in actual import modules. |
||||
|
""" |
||||
|
|
||||
|
def _test_transaction( |
||||
|
self, statement_obj, remote_account=False, |
||||
|
transferred_amount=False, value_date=False, ref=False): |
||||
|
"""Check wether transaction with attributes passed was created. |
||||
|
|
||||
|
Actually this method also tests wether automatic creation of |
||||
|
partner bank accounts is working. |
||||
|
""" |
||||
|
transaction_model = self.env['account.bank.statement.line'] |
||||
|
partner_bank_model = self.env['res.partner.bank'] |
||||
|
domain = [('statement_id', '=', statement_obj.id)] |
||||
|
if remote_account: |
||||
|
bids = partner_bank_model.search( |
||||
|
[('acc_number', '=', remote_account)]) |
||||
|
self.assertTrue( |
||||
|
bids, |
||||
|
'Bank-account %s not found after parse.' % remote_account |
||||
|
) |
||||
|
domain.append(('bank_account_id', '=', bids[0].id)) |
||||
|
if transferred_amount: |
||||
|
domain.append(('amount', '=', transferred_amount)) |
||||
|
if value_date: |
||||
|
domain.append(('date', '=', value_date)) |
||||
|
if ref: |
||||
|
domain.append(('ref', '=', ref)) |
||||
|
ids = transaction_model.search(domain) |
||||
|
if not ids: |
||||
|
# We will get assertion error, but to solve we need to see |
||||
|
# what transactions have been added: |
||||
|
self.cr.execute( |
||||
|
"select name, date, amount, ref, bank_account_id" |
||||
|
" from account_bank_statement_line" |
||||
|
" where statement_id=%d" % statement_obj.id) |
||||
|
_LOGGER.error( |
||||
|
"Transaction not found in %s" % |
||||
|
str(self.cr.fetchall()) |
||||
|
) |
||||
|
self.assertTrue( |
||||
|
ids, |
||||
|
'Transaction %s not found after parse.' % str(domain) |
||||
|
) |
||||
|
|
||||
|
def _test_statement_import( |
||||
|
self, module_name, file_name, statement_name, local_account=False, |
||||
|
start_balance=False, end_balance=False, transactions=None): |
||||
|
"""Test correct creation of single statement.""" |
||||
|
import_model = self.env['account.bank.statement.import'] |
||||
|
partner_bank_model = self.env['res.partner.bank'] |
||||
|
statement_model = self.env['account.bank.statement'] |
||||
|
statement_path = get_module_resource( |
||||
|
module_name, |
||||
|
'test_files', |
||||
|
file_name |
||||
|
) |
||||
|
statement_file = open( |
||||
|
statement_path, 'rb').read().encode('base64') |
||||
|
bank_statement_id = import_model.create( |
||||
|
dict( |
||||
|
data_file=statement_file, |
||||
|
) |
||||
|
) |
||||
|
bank_statement_id.import_file() |
||||
|
# Check wether bank account has been created: |
||||
|
if local_account: |
||||
|
bids = partner_bank_model.search( |
||||
|
[('acc_number', '=', local_account)]) |
||||
|
self.assertTrue( |
||||
|
bids, |
||||
|
'Bank account %s not created from statement' % local_account |
||||
|
) |
||||
|
# statement name is account number + '-' + date of last 62F line: |
||||
|
ids = statement_model.search([('name', '=', statement_name)]) |
||||
|
self.assertTrue( |
||||
|
ids, |
||||
|
'Statement %s not found after parse.' % statement_name |
||||
|
) |
||||
|
statement_obj = ids[0] |
||||
|
#statement_obj = statement_model.browse(statement_id) |
||||
|
if start_balance: |
||||
|
self.assertTrue( |
||||
|
abs(statement_obj.balance_start - start_balance) < 0.00001, |
||||
|
'Start balance %f not equal to expected %f' % |
||||
|
(statement_obj.balance_start, start_balance) |
||||
|
) |
||||
|
if end_balance: |
||||
|
self.assertTrue( |
||||
|
abs(statement_obj.balance_end_real - end_balance) < 0.00001, |
||||
|
'End balance %f not equal to expected %f' % |
||||
|
(statement_obj.balance_end_real, end_balance) |
||||
|
) |
||||
|
# Maybe we need to test transactions? |
||||
|
if transactions: |
||||
|
for transaction in transactions: |
||||
|
self._test_transaction(statement_obj, **transaction) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue