Browse Source

The import must fail if the bank_account or the account_journal is not found

The creation of account_journal and bank_account must be prohibited when importing statments.
pull/37/head
Laurent Mignon (ACSONE) 9 years ago
parent
commit
43dd1a3f60
  1. 13
      account_bank_statement_import/models/account_bank_statement_import.py
  2. 19
      account_bank_statement_import/tests/test_import_bank_statement.py
  3. 6
      account_bank_statement_import_mt940_nl_rabo/tests/test_import_bank_statement.py

13
account_bank_statement_import/models/account_bank_statement_import.py

@ -110,17 +110,10 @@ class AccountBankStatementImport(models.TransientModel):
# Try to find the bank account and currency in odoo
currency_id = self._find_currency_id(currency_code)
bank_account_id = self._find_bank_account_id(account_number)
# Create the bank account if not already existing
if not bank_account_id and account_number:
journal_id = self.env.context.get('journal_id')
company_id = self.env.user.company_id.id
if journal_id:
journal = self.env['account.journal'].browse(journal_id)
company_id = journal.company_id.id
bank_account_id = self._create_bank_account(
account_number, company_id=company_id,
currency_id=currency_id).id
# Find or create the bank journal
raise Warning(_('Can not find the account number %s.') %
account_number)
# Find the bank journal
journal_id = self._get_journal(currency_id, bank_account_id)
# By now journal and account_number must be known
if not journal_id:

19
account_bank_statement_import/tests/test_import_bank_statement.py

@ -23,6 +23,7 @@
#
##############################################################################
from openerp.tests.common import TransactionCase
from openerp.exceptions import Warning
class TestAccountBankStatementImport(TransactionCase):
@ -59,6 +60,24 @@ class TestAccountBankStatementImport(TransactionCase):
"groups_id": [(4, self.ref('account.group_account_manager'))]
})
def test_import_preconditions(self):
"""Checks that the import raises an exception if:
* no bank account found for the account_number
* no account_journal found on the bank_account
"""
stmt_vals = {
'currency_code': 'EUR',
'account_number': '123456789'}
with self.assertRaises(Warning) as e:
self.statement_import_model._import_statement(stmt_vals.copy())
self.assertEqual(e.exception.message,
'Can not find the account number 123456789.')
self.statement_import_model._create_bank_account('123456789')
with self.assertRaises(Warning) as e:
self.statement_import_model._import_statement(stmt_vals.copy())
self.assertEqual(e.exception.message,
'Can not determine journal for import.')
def test_create_bank_account(self):
"""Checks that the bank_account created by the import belongs to the
partner linked to the company of the provided journal

6
account_bank_statement_import_mt940_nl_rabo/tests/test_import_bank_statement.py

@ -26,6 +26,12 @@ from openerp.addons.account_bank_statement_import.tests import (
class TestImport(TestStatementFile):
"""Run test to import MT940 RABO import."""
def setUp(self):
super(TestImport, self).setUp()
import_wizard = self.env['account.bank.statement.import']
import_wizard._create_bank_account(
'NL34RABO0142623393', company_id=self.env.user.company_id.id)
def test_statement_import(self):
"""Test correct creation of single statement."""
transactions = [

Loading…
Cancel
Save