Browse Source

[FIX] Minimize changes for enhanced unique id.

pull/153/head
Ronald Portier 8 years ago
parent
commit
efe4e09473
  1. 22
      account_bank_statement_import/models/account_bank_statement_import.py
  2. 3
      account_bank_statement_import_camt/__init__.py
  3. 22
      account_bank_statement_import_camt/__openerp__.py
  4. 27
      account_bank_statement_import_camt/models/account_bank_statement_import.py
  5. 25
      account_bank_statement_import_camt/tests/__init__.py
  6. 21
      account_bank_statement_import_camt/tests/test_import_bank_statement.py

22
account_bank_statement_import/models/account_bank_statement_import.py

@ -151,13 +151,13 @@ class AccountBankStatementImport(models.TransientModel):
account_number = stmt_vals.pop('account_number')
# Try to find the bank account and currency in odoo
currency_id = self._find_currency_id(currency_code)
statement_bank = self._get_bank(account_number)
if not statement_bank and account_number:
bank_account_id = self._find_bank_account_id(account_number)
if not bank_account_id and account_number:
raise UserError(
_('Can not find the account number %s.') % account_number
)
# Find the bank journal
journal_id = self._get_journal(currency_id, statement_bank.id)
journal_id = self._get_journal(currency_id, bank_account_id)
# By now journal and account_number must be known
if not journal_id:
raise UserError(
@ -167,8 +167,7 @@ class AccountBankStatementImport(models.TransientModel):
)
# Prepare statement data to be used for bank statements creation
stmt_vals = self._complete_statement(
statement_bank, stmt_vals, journal_id
)
stmt_vals, journal_id, account_number)
# Create the bank stmt_vals
return self._create_bank_statement(stmt_vals)
@ -246,6 +245,17 @@ class AccountBankStatementImport(models.TransientModel):
)
return bank_model.browse([]) # Empty recordset
@api.model
def _find_bank_account_id(self, account_number):
""" Get res.partner.bank ID """
bank_account_id = None
if account_number and len(account_number) > 4:
bank_account_ids = self.env['res.partner.bank'].search(
[('acc_number', '=', account_number)], limit=1)
if bank_account_ids:
bank_account_id = bank_account_ids[0].id
return bank_account_id
@api.model
def _get_journal(self, currency_id, bank_account_id):
""" Find the journal """
@ -336,7 +346,7 @@ class AccountBankStatementImport(models.TransientModel):
default_currency=currency_id).create(vals_acc)
@api.model
def _complete_statement(self, statement_bank, stmt_vals, journal_id):
def _complete_statement(self, stmt_vals, journal_id, account_number):
"""Complete statement from information passed."""
stmt_vals['journal_id'] = journal_id
statement_bank = self._get_bank(account_number)

3
account_bank_statement_import_camt/__init__.py

@ -1 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2013-2018 Therp BV <http://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

22
account_bank_statement_import_camt/__openerp__.py

@ -1,26 +1,10 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013-2015 Therp BV <http://therp.nl>
#
# 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/>.
#
##############################################################################
# © 2013-2017 Therp BV <http://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'CAMT Format Bank Statements Import',
'version': '8.0.0.4.1',
'summary': 'Module to import SEPA CAMT.053 Format bank statement files',
'version': '8.0.0.4.1',
'license': 'AGPL-3',
'author': 'Odoo Community Association (OCA), Therp BV',
'website': 'https://github.com/OCA/bank-statement-import',

27
account_bank_statement_import_camt/models/account_bank_statement_import.py

@ -1,24 +1,8 @@
# -*- coding: utf-8 -*-
"""Add process_camt method to account.bank.statement.import."""
##############################################################################
#
# Copyright (C) 2013-2015 Therp BV <http://therp.nl>
#
# 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/>.
#
##############################################################################
# © 2013-2017 Therp BV <http://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from openerp import models
_logger = logging.getLogger(__name__)
@ -36,7 +20,8 @@ class AccountBankStatementImport(models.TransientModel):
return parser.parse(data_file)
except ValueError:
# Not a camt file, returning super will call next candidate:
_logger.debug("Statement file was not a camt file.",
exc_info=True)
_logger.debug(
"Statement file was not a camt file.", exc_info=True
)
return super(AccountBankStatementImport, self)._parse_file(
cr, uid, data_file, context=context)

25
account_bank_statement_import_camt/tests/__init__.py

@ -1,23 +1,4 @@
# -*- encoding: utf-8 -*-
"""Test import of bank statement for camt.053."""
##############################################################################
#
# Copyright (C) 2015 Therp BV <http://therp.nl>.
#
# All other contributions are (C) by their respective contributors
#
# 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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2015-2017 Therp BV <http://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_import_bank_statement

21
account_bank_statement_import_camt/tests/test_import_bank_statement.py

@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
"""Run test to import camt.053 import."""
##############################################################################
#
# Copyright (C) 2015 Therp BV <http://therp.nl>.
#
# 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/>.
#
##############################################################################
# © 2015-2017 Therp BV <http://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.addons.account_bank_statement_import.tests import (
TestStatementFile)

Loading…
Cancel
Save