Browse Source

Merge pull request #37 from acsone/8.0-fix-prevent-create-bank_anccount-and-account_journal-lmi

The import must fail if the bank_account or the account_journal is no…
pull/38/head
Pedro M. Baeza 9 years ago
parent
commit
a1e7e10ef2
  1. 2
      account_bank_statement_import/__openerp__.py
  2. 13
      account_bank_statement_import/models/account_bank_statement_import.py
  3. 19
      account_bank_statement_import/tests/test_import_bank_statement.py
  4. 6
      account_bank_statement_import_mt940_nl_rabo/tests/test_import_bank_statement.py

2
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',

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