Giedrius Slavinskas
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 188 additions and 0 deletions
-
47account_bank_statement_import_mt940_uk_hsbc/README.rst
-
110account_bank_statement_import_mt940_uk_hsbc/__init__.py
-
31account_bank_statement_import_mt940_uk_hsbc/__openerp__.py
@ -0,0 +1,47 @@ |
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|||
:alt: License: AGPL-3 |
|||
|
|||
Import MT940 UK HSBC Bank Statements |
|||
===================================== |
|||
|
|||
This module allows you to import the MT940 files from the UK HSBC bank |
|||
in Odoo as bank statements. |
|||
|
|||
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 smashing it by providing a detailed and welcomed feedback |
|||
`here <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_bank_statement_import%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
|||
|
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Giedrius Slavinskas <giedrius@inovera.lt> |
|||
|
|||
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 http://odoo-community.org. |
|||
This module should make it easy to migrate bank statement import |
|||
modules written for earlies versions of Odoo/OpenERP. |
@ -0,0 +1,110 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2017 Giedrius Slavinskas <giedrius@inovera.lt> |
|||
# |
|||
# 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/>. |
|||
# |
|||
############################################################################## |
|||
import re |
|||
import logging |
|||
from openerp import models |
|||
from openerp.addons.account_bank_statement_import_mt940_base.mt940 import ( |
|||
MT940, str2amount) |
|||
|
|||
|
|||
logger = logging.getLogger(__name__) |
|||
|
|||
tag_61_regex = re.compile( |
|||
r'^(?P<date>\d{6})(?P<line_date>\d{0,4})?' |
|||
r'(?P<sign>[CD])(?P<currency>[A-Z])?(?P<amount>\d+,\d{2})N' |
|||
r'(?P<type>.{3})(?P<reference>.{16})//(?P<bankref>.{16})(?P<info>.*)' |
|||
) |
|||
|
|||
|
|||
class MT940Parser(MT940): |
|||
"""Parser for ing MT940 bank statement import files.""" |
|||
|
|||
def __init__(self): |
|||
"""Initialize parser - override at least header_regex.""" |
|||
super(MT940Parser, self).__init__() |
|||
self.mt940_type = 'UK HSBC' |
|||
self.header_lines = 0 |
|||
self.header_regex = '^:20:\d{6}' |
|||
self.footer_regex = '^:62F:' |
|||
|
|||
def handle_tag_20(self, data): |
|||
"""get bank statment file reference""" |
|||
super(MT940Parser, self).handle_header(data, None) |
|||
self.current_statement.ref = data.strip() |
|||
|
|||
def handle_tag_25(self, data): |
|||
"""parse local bank account number of the bank statment""" |
|||
data = data.strip() |
|||
self.current_statement.local_account = ' '.join([data[:6], |
|||
data[6:].zfill(8)]) |
|||
|
|||
def handle_tag_28C(self, data): |
|||
"""get bank statment file number""" |
|||
self.current_statement.number = data.strip() |
|||
|
|||
def handle_tag_61(self, data): |
|||
"""get transaction values""" |
|||
super(MT940Parser, self).handle_tag_61(data) |
|||
|
|||
match = tag_61_regex.match(data) |
|||
if not match: |
|||
raise ValueError("Cannot parse %s" % data) |
|||
res = match.groupdict() |
|||
|
|||
transaction = self.current_transaction |
|||
transaction.transferred_amount = str2amount(res['sign'], res['amount']) |
|||
transaction.transfer_type = res['type'] |
|||
|
|||
res['reference'] = res['reference'].strip() |
|||
if res['reference'] and res['reference'] != 'NONREF': |
|||
transaction.eref = res['reference'] |
|||
|
|||
def handle_tag_86(self, data): |
|||
"""set additional info""" |
|||
self.current_transaction.message = ' '.join(data.split()) |
|||
|
|||
def handle_header(self, dummy_line, iterator): |
|||
pass |
|||
|
|||
def handle_footer(self, dummy_line, dummy_iterator): |
|||
self.handle_record(dummy_line) |
|||
statement = self.current_statement |
|||
statement.statement_id = '%s-%s-%s' % ( |
|||
statement.ref, statement.local_account, statement.number |
|||
) |
|||
super(MT940Parser, self).handle_footer(dummy_line, dummy_iterator) |
|||
|
|||
|
|||
class AccountBankStatementImport(models.TransientModel): |
|||
"""Add parsing of mt940 files to bank statement import.""" |
|||
_inherit = 'account.bank.statement.import' |
|||
|
|||
def _parse_file(self, cr, uid, data_file, context=None): |
|||
"""Parse a MT940 UK HSBC file.""" |
|||
parser = MT940Parser() |
|||
try: |
|||
logger.debug("Try parsing with MT940 UK HSBC.") |
|||
return parser.parse(data_file) |
|||
except ValueError: |
|||
# Returning super will call next candidate: |
|||
logger.debug("Statement file was not a MT940 UK HSBC file.", |
|||
exc_info=True) |
|||
return super(AccountBankStatementImport, self)._parse_file( |
|||
cr, uid, data_file, context=context) |
@ -0,0 +1,31 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2017 Giedrius Slavinskas <giedrius@inovera.lt> |
|||
# |
|||
# 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/>. |
|||
# |
|||
############################################################################## |
|||
{ |
|||
'name': 'MT940 UK HSBC Format Bank Statements Import', |
|||
'version': '8.0.0.0.0', |
|||
'license': 'AGPL-3', |
|||
'author': 'Giedrius Slavinskas', |
|||
'website': 'https://github.com/OCA/bank-statement-import', |
|||
'category': 'Banking addons', |
|||
'depends': [ |
|||
'account_bank_statement_import_mt940_base' |
|||
], |
|||
'installable': True, |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue