From 43dd1a3f60dddd6f4d711aea6ef7776d8aa81df8 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 30 Sep 2015 12:39:30 +0200 Subject: [PATCH 1/2] 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. --- .../models/account_bank_statement_import.py | 13 +++---------- .../tests/test_import_bank_statement.py | 19 +++++++++++++++++++ .../tests/test_import_bank_statement.py | 6 ++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/account_bank_statement_import/models/account_bank_statement_import.py b/account_bank_statement_import/models/account_bank_statement_import.py index b002fa7..3d2e8f7 100644 --- a/account_bank_statement_import/models/account_bank_statement_import.py +++ b/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: diff --git a/account_bank_statement_import/tests/test_import_bank_statement.py b/account_bank_statement_import/tests/test_import_bank_statement.py index 76ca660..e32051a 100644 --- a/account_bank_statement_import/tests/test_import_bank_statement.py +++ b/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 diff --git a/account_bank_statement_import_mt940_nl_rabo/tests/test_import_bank_statement.py b/account_bank_statement_import_mt940_nl_rabo/tests/test_import_bank_statement.py index 476b0a6..0ecf718 100644 --- a/account_bank_statement_import_mt940_nl_rabo/tests/test_import_bank_statement.py +++ b/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 = [ From 21a5875f43d9d62b1e26e9e60590deee67da3df0 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 30 Sep 2015 17:01:55 +0200 Subject: [PATCH 2/2] Bump version number --- account_bank_statement_import/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_bank_statement_import/__openerp__.py b/account_bank_statement_import/__openerp__.py index 46c9466..b7a9557 100644 --- a/account_bank_statement_import/__openerp__.py +++ b/account_bank_statement_import/__openerp__.py @@ -2,7 +2,7 @@ { 'name': 'Account Bank Statement Import', 'category': 'Banking addons', - 'version': '1.0', + 'version': '8.0.1.0.1', 'author': 'OpenERP SA,' 'Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/bank-statement-import',