mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[FIX] Now succesfully running tests for all imports.
This commit is contained in:
@@ -212,21 +212,36 @@ class AccountBankStatementImport(models.TransientModel):
|
||||
else:
|
||||
if bank_account.journal_id.id:
|
||||
journal_id = bank_account.journal_id.id
|
||||
|
||||
# If importing into an existing journal, its currency must be the same
|
||||
# as the bank statement
|
||||
if journal_id:
|
||||
journal_currency_id = self.env['account.journal'].browse(
|
||||
journal_id).currency.id
|
||||
if currency_id and currency_id != journal_currency_id:
|
||||
raise Warning(_('The currency of the bank statement is not '
|
||||
'the same as the currency of the journal !'))
|
||||
|
||||
# If we couldn't find/create a journal, everything is lost
|
||||
if not journal_id:
|
||||
raise Warning(_('Cannot find in which journal import this '
|
||||
'statement. Please manually select a journal.'))
|
||||
|
||||
# as the bank statement. When journal has no currency, currency must
|
||||
# be equal to company currency.
|
||||
if journal_id and currency_id:
|
||||
journal_obj = self.env['account.journal'].browse(journal_id)
|
||||
if journal_obj.currency:
|
||||
if currency_id != journal_obj.currency.id:
|
||||
# ALso log message with id's for technical analysis:
|
||||
_logger.warn(_(
|
||||
'Statement currency id is %d,'
|
||||
' but journal currency id = %d.') %
|
||||
(currency_id, journal_currency_id,)
|
||||
)
|
||||
raise Warning(_(
|
||||
'The currency of the bank statement is not '
|
||||
'the same as the currency of the journal !'
|
||||
))
|
||||
else:
|
||||
company_currency_id = self.env.user.company_id.currency_id.id
|
||||
if currency_id != company_currency_id:
|
||||
# ALso log message with id's for technical analysis:
|
||||
_logger.warn(_(
|
||||
'Statement currency id is %d,'
|
||||
' but company currency id = %d.') %
|
||||
(currency_id, company_currency_id,)
|
||||
)
|
||||
raise Warning(_(
|
||||
'The currency of the bank statement is not '
|
||||
'the same as the company currency !'
|
||||
))
|
||||
return journal_id
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
from openerp.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestAccountBankStatemetImport(TransactionCase):
|
||||
class TestAccountBankStatementImport(TransactionCase):
|
||||
"""Tests for import bank statement file import
|
||||
(account.bank.statement.import)
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccountBankStatemetImport, self).setUp()
|
||||
super(TestAccountBankStatementImport, self).setUp()
|
||||
self.statement_import_model = self.env[
|
||||
'account.bank.statement.import']
|
||||
self.account_journal_model = self.env['account.journal']
|
||||
|
||||
@@ -31,7 +31,7 @@ def convert_transaction(transaction):
|
||||
'ref': transaction.eref,
|
||||
'amount': transaction.transferred_amount,
|
||||
'partner_name': transaction.remote_owner,
|
||||
'acc_number': transaction.remote_account,
|
||||
'account_number': transaction.remote_account,
|
||||
'unique_import_id': transaction.transaction_id,
|
||||
}
|
||||
return vals_line
|
||||
|
||||
@@ -252,7 +252,7 @@ class MT940(object):
|
||||
stmt = self.current_statement
|
||||
stmt.end_balance = str2amount(data[0], data[10:])
|
||||
stmt.date = datetime.strptime(data[1:7], '%y%m%d')
|
||||
stmt.id = '%s-%s' % (
|
||||
stmt.statement_id = '%s-%s' % (
|
||||
stmt.local_account,
|
||||
stmt.date.strftime('%Y-%m-%d'),
|
||||
)
|
||||
|
||||
@@ -28,5 +28,8 @@
|
||||
'bank_statement_parse_mt940'
|
||||
],
|
||||
'data': [],
|
||||
'demo': [
|
||||
'demo/demo_data.xml',
|
||||
],
|
||||
'installable': True
|
||||
}
|
||||
|
||||
26
bank_statement_parse_nl_ing_mt940/demo/demo_data.xml
Normal file
26
bank_statement_parse_nl_ing_mt940/demo/demo_data.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="mt940_ing_bank_journal" model="account.journal">
|
||||
<field name="name">Bank Journal - (test mt940 ING)</field>
|
||||
<field name="code">TBNKMT940ING</field>
|
||||
<field name="type">bank</field>
|
||||
<field name="sequence_id" ref="account.sequence_bank_journal"/>
|
||||
<field name="default_debit_account_id" ref="account.bnk"/>
|
||||
<field name="default_credit_account_id" ref="account.bnk"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
</record>
|
||||
|
||||
<record id="mt940_ing_company_bank" model="res.partner.bank">
|
||||
<field name="owner_name">Your Company</field>
|
||||
<field name="acc_number">NL77ABNA0574908765</field>
|
||||
<field name="partner_id" ref="base.partner_root"></field>
|
||||
<field name="company_id" ref="base.main_company"></field>
|
||||
<field name="journal_id" ref="mt940_ing_bank_journal"></field>
|
||||
<field name="state">bank</field>
|
||||
<field name="bank" ref="base.res_bank_1"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
</openerp>
|
||||
@@ -48,8 +48,9 @@ class TestStatementFile(TransactionCase):
|
||||
)
|
||||
)
|
||||
import_model.import_file(cr, uid, [bank_statement_id])
|
||||
# statement name is account number + '-' + date of last 62F line:
|
||||
ids = statement_model.search(
|
||||
cr, uid, [('name', '=', '2014-02-19/00000')])
|
||||
cr, uid, [('name', '=', 'NL77ABNA0574908765-2014-02-20')])
|
||||
self.assertTrue(ids, 'Statement not found after parse.')
|
||||
statement_id = ids[0]
|
||||
statement_obj = statement_model.browse(
|
||||
|
||||
29
bank_statement_parse_nl_rabo_mt940/test_files/test-rabo.swi
Normal file
29
bank_statement_parse_nl_rabo_mt940/test_files/test-rabo.swi
Normal file
@@ -0,0 +1,29 @@
|
||||
:940:
|
||||
:20:940S140102
|
||||
:25:NL34RABO0142623393 EUR
|
||||
:28C:0
|
||||
:60F:C131231EUR000000004433,52
|
||||
:61:140102C000000000400,00N541NONREF
|
||||
NL66RABO0160878799
|
||||
:86:/ORDP//NAME/R. SMITH/ADDR/Green market 74 3311BE Sheepcity Nederl
|
||||
and NL/REMI/Test money paid by other partner:
|
||||
/ISDT/2014-01-02
|
||||
:62F:C140102EUR000000004833,52
|
||||
:20:940S140103
|
||||
:25:NL34RABO0142623393 EUR
|
||||
:28C:0
|
||||
:60F:C140102EUR000000004833,52
|
||||
:62F:C140103EUR000000004833,52
|
||||
:20:940S140106
|
||||
:25:NL34RABO0142623393 EUR
|
||||
:28C:0
|
||||
:60F:C140103EUR000000004833,52
|
||||
:61:140101D000000000034,61N093NONREF
|
||||
:86:/BENM//NAME/Kosten/REMI/Periode 01-10-2013 t/m 31-12-2013/ISDT/20
|
||||
14-01-01
|
||||
:62F:C140106EUR000000004798,91
|
||||
:20:940S140107
|
||||
:25:NL34RABO0142623393 EUR
|
||||
:28C:0
|
||||
:60F:C140106EUR000000004798,91
|
||||
:62F:C140107EUR000000004798,91
|
||||
25
bank_statement_parse_nl_rabo_mt940/tests/__init__.py
Normal file
25
bank_statement_parse_nl_rabo_mt940/tests/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""Test import of bank statement for MT940 ING."""
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# All other contributions are (C) by their respective contributors
|
||||
#
|
||||
# All Rights Reserved
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
from . import test_import_bank_statement
|
||||
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Run test to import MT940 IBAN RABO import."""
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# All other contributions are (C) by their respective contributors
|
||||
#
|
||||
# All Rights Reserved
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.tests.common import TransactionCase
|
||||
from openerp.modules.module import get_module_resource
|
||||
|
||||
|
||||
class TestStatementFile(TransactionCase):
|
||||
"""Run test to import MT940 RABO import."""
|
||||
|
||||
def test_statement_import(self):
|
||||
"""Test correct creation of single statement.
|
||||
|
||||
For this test there is NOT an existing bank-account. Therefore a
|
||||
bank account should automatically be created in the main company.
|
||||
"""
|
||||
partner_bank_model = self.env['res.partner.bank']
|
||||
import_model = self.registry('account.bank.statement.import')
|
||||
statement_model = self.registry('account.bank.statement')
|
||||
cr, uid = self.cr, self.uid
|
||||
statement_path = get_module_resource(
|
||||
'bank_statement_parse_nl_rabo_mt940',
|
||||
'test_files',
|
||||
'test-rabo.swi'
|
||||
)
|
||||
statement_file = open(
|
||||
statement_path, 'rb').read().encode('base64')
|
||||
bank_statement_id = import_model.create(
|
||||
cr, uid,
|
||||
dict(
|
||||
data_file=statement_file,
|
||||
)
|
||||
)
|
||||
import_model.import_file(cr, uid, [bank_statement_id])
|
||||
# Check wether bank account has been created:
|
||||
vals = partner_bank_model.search(
|
||||
[('acc_number', '=', 'NL34RABO0142623393')])
|
||||
self.assertEquals(
|
||||
1, len(vals),
|
||||
'Bank account not created from statement'
|
||||
)
|
||||
# statement name is account number + '-' + date of last 62F line:
|
||||
ids = statement_model.search(
|
||||
cr, uid, [('name', '=', 'NL34RABO0142623393-2014-01-07')])
|
||||
self.assertTrue(ids, 'Statement not found after parse.')
|
||||
statement_id = ids[0]
|
||||
statement_obj = statement_model.browse(
|
||||
cr, uid, statement_id)
|
||||
self.assertTrue(
|
||||
abs(statement_obj.balance_start - 4433.52) < 0.00001,
|
||||
'Start balance %f not equal to 4433.52' %
|
||||
statement_obj.balance_start
|
||||
)
|
||||
self.assertTrue(
|
||||
abs(statement_obj.balance_end_real - 4798.91) < 0.00001,
|
||||
'Real end balance %f not equal to 4798.91' %
|
||||
statement_obj.balance_end_real
|
||||
)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
Reference in New Issue
Block a user