mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
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.
This commit is contained in:
@@ -110,17 +110,10 @@ class AccountBankStatementImport(models.TransientModel):
|
|||||||
# Try to find the bank account and currency in odoo
|
# Try to find the bank account and currency in odoo
|
||||||
currency_id = self._find_currency_id(currency_code)
|
currency_id = self._find_currency_id(currency_code)
|
||||||
bank_account_id = self._find_bank_account_id(account_number)
|
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:
|
if not bank_account_id and account_number:
|
||||||
journal_id = self.env.context.get('journal_id')
|
raise Warning(_('Can not find the account number %s.') %
|
||||||
company_id = self.env.user.company_id.id
|
account_number)
|
||||||
if journal_id:
|
# Find the bank journal
|
||||||
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
|
|
||||||
journal_id = self._get_journal(currency_id, bank_account_id)
|
journal_id = self._get_journal(currency_id, bank_account_id)
|
||||||
# By now journal and account_number must be known
|
# By now journal and account_number must be known
|
||||||
if not journal_id:
|
if not journal_id:
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
from openerp.tests.common import TransactionCase
|
from openerp.tests.common import TransactionCase
|
||||||
|
from openerp.exceptions import Warning
|
||||||
|
|
||||||
|
|
||||||
class TestAccountBankStatementImport(TransactionCase):
|
class TestAccountBankStatementImport(TransactionCase):
|
||||||
@@ -59,6 +60,24 @@ class TestAccountBankStatementImport(TransactionCase):
|
|||||||
"groups_id": [(4, self.ref('account.group_account_manager'))]
|
"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):
|
def test_create_bank_account(self):
|
||||||
"""Checks that the bank_account created by the import belongs to the
|
"""Checks that the bank_account created by the import belongs to the
|
||||||
partner linked to the company of the provided journal
|
partner linked to the company of the provided journal
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ from openerp.addons.account_bank_statement_import.tests import (
|
|||||||
class TestImport(TestStatementFile):
|
class TestImport(TestStatementFile):
|
||||||
"""Run test to import MT940 RABO import."""
|
"""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):
|
def test_statement_import(self):
|
||||||
"""Test correct creation of single statement."""
|
"""Test correct creation of single statement."""
|
||||||
transactions = [
|
transactions = [
|
||||||
|
|||||||
Reference in New Issue
Block a user