Skip to content

Commit

Permalink
Merge 75cdc9d into c6753bd
Browse files Browse the repository at this point in the history
  • Loading branch information
feketemihai committed Dec 8, 2019
2 parents c6753bd + 75cdc9d commit 77698f3
Show file tree
Hide file tree
Showing 14 changed files with 695 additions and 0 deletions.
Empty file added __init__.py
Empty file.
55 changes: 55 additions & 0 deletions account_bank_statement_import_mt940_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

====================
Bank Statement MT940
====================

This module provides a generic parser for MT940 files. Given that MT940 is a
non-open non-standard of pure evil in the way that every bank cooks up its own
interpretation of it, this addon alone won't help you much. It is rather
intended to be used by other addons to implement the dialect specific to a
certain bank.

See account_bank_statement_import_mt940_nl_ing for an example on how to use it.

Known issues / Roadmap
======================

* None

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/bank-statement-import/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Stefan Rijnhart <srijnhart@therp.nl>
* Ronald Portier <rportier@therp.nl>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Fekete Mihai <mihai.fekete@gmail.com>

Maintainer
----------


.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
1 change: 1 addition & 0 deletions account_bank_statement_import_mt940_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions account_bank_statement_import_mt940_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2013-2015 Therp BV <http://therp.nl>

{
'name': 'MT940 Bank Statements Import',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'author': 'Odoo Community Association (OCA), Therp BV',
'website': 'https://github.com/OCA/bank-statement-import',
'category': 'Banking addons',
'depends': [
'account_bank_statement_import',
],
'installable': True
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

3 changes: 3 additions & 0 deletions account_bank_statement_import_mt940_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import account_bank_statement_import
from . import account_journal
from . import mt940
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2019 OdooERP Romania <https://odooerpromania.ro>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from io import BytesIO
import zipfile
from odoo import api, models

_logger = logging.getLogger(__name__)


class AccountBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import'

@api.model
def _parse_file(self, data_file):
"""Parse a MT940 file.
For different type of MT940 statement add the type in the context.
and check methods return depending on get_mt940_type() """
try:
parser = self.env['account.bank.statement.import.mt940.parser']
_logger.debug("Try parsing with mt940.")
parser = parser.with_context(type='mt940_general')
return parser.parse(data_file)
except ValueError:
try:
with zipfile.ZipFile(BytesIO(data_file)) as data:
currency = None
account_number = None
transactions = []
for member in data.namelist():
currency, account_number, new = self._parse_file(
data.open(member).read()
)
transactions.extend(new)
return currency, account_number, transactions
except (zipfile.BadZipFile, ValueError):
pass
# Not a mt940 file, returning super will call next candidate:
_logger.debug("Statement file was not a mt940 file.",
exc_info=True)
return super(AccountBankStatementImport, self)._parse_file(data_file)
14 changes: 14 additions & 0 deletions account_bank_statement_import_mt940_base/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2019 OdooERP Romania <https://odooerpromania.ro>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, _


class AccountJournal(models.Model):
_inherit = "account.journal"

def _get_bank_statements_available_import_formats(self):
res = super(AccountJournal, self).\
_get_bank_statements_available_import_formats()
res.extend([_('mt940')])
return res

0 comments on commit 77698f3

Please sign in to comment.