diff --git a/account_bank_statement_import_camt/README.rst b/account_bank_statement_import_camt/README.rst index 92aaeaa..327bd47 100644 --- a/account_bank_statement_import_camt/README.rst +++ b/account_bank_statement_import_camt/README.rst @@ -1,6 +1,8 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: https://www.gnu.com/licenses/agpl :alt: License: AGPL-3 +========================= Bank Statement Parse Camt ========================= @@ -8,18 +10,16 @@ Module to import SEPA CAMT.053 and CAMT.054 Format bank statement files. Based on the Banking addons framework. -Known issues / Roadmap -====================== +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/174/11.0 -* None Bug Tracker =========== Bugs are tracked on `GitHub 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 `_. +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 a detailed and welcomed feedback. Credits @@ -31,6 +31,10 @@ Contributors * Holger Brunn * Stefan Rijnhart * Ronald Portier +* Andrea Stirpe +* Maxence Groine + +Do not contact contributors directly about support or help with technical issues. Maintainer ---------- @@ -46,5 +50,3 @@ 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. diff --git a/account_bank_statement_import_camt/__init__.py b/account_bank_statement_import_camt/__init__.py index 1eb5270..867022b 100644 --- a/account_bank_statement_import_camt/__init__.py +++ b/account_bank_statement_import_camt/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2013-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/account_bank_statement_import_camt/__manifest__.py b/account_bank_statement_import_camt/__manifest__.py index 1a4d512..f2ca11a 100644 --- a/account_bank_statement_import_camt/__manifest__.py +++ b/account_bank_statement_import_camt/__manifest__.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # © 2013-2017 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'CAMT Format Bank Statements Import', - 'version': '10.0.1.1.1', + 'version': '11.0.1.0.0', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', diff --git a/account_bank_statement_import_camt/models/__init__.py b/account_bank_statement_import_camt/models/__init__.py index 0251c8f..8b7d2c6 100644 --- a/account_bank_statement_import_camt/models/__init__.py +++ b/account_bank_statement_import_camt/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2013-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import parser diff --git a/account_bank_statement_import_camt/models/account_bank_statement_import.py b/account_bank_statement_import_camt/models/account_bank_statement_import.py index 4490f16..27b26af 100644 --- a/account_bank_statement_import_camt/models/account_bank_statement_import.py +++ b/account_bank_statement_import_camt/models/account_bank_statement_import.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- """Add process_camt method to account.bank.statement.import.""" # © 2013-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging -import StringIO +from io import BytesIO import zipfile from odoo import api, models @@ -23,7 +22,7 @@ class AccountBankStatementImport(models.TransientModel): return parser.parse(data_file) except ValueError: try: - with zipfile.ZipFile(StringIO.StringIO(data_file)) as data: + with zipfile.ZipFile(BytesIO(data_file)) as data: currency = None account_number = None transactions = [] diff --git a/account_bank_statement_import_camt/models/parser.py b/account_bank_statement_import_camt/models/parser.py index c98e715..0668422 100644 --- a/account_bank_statement_import_camt/models/parser.py +++ b/account_bank_statement_import_camt/models/parser.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Class to parse camt files.""" # © 2013-2016 Therp BV # Copyright 2017 Open Net Sàrl @@ -10,8 +9,8 @@ from odoo import models class CamtParser(models.AbstractModel): - _name = 'account.bank.statement.import.camt.parser' """Parser for camt bank statement import files.""" + _name = 'account.bank.statement.import.camt.parser' def parse_amount(self, ns, node): """Parse element that contains Amount and CreditDebitIndicator.""" @@ -190,14 +189,14 @@ class CamtParser(models.AbstractModel): def check_version(self, ns, root): """Validate validity of camt file.""" - # Check wether it is camt at all: + # Check whether it is camt at all: re_camt = re.compile( r'(^urn:iso:std:iso:20022:tech:xsd:camt.' r'|^ISO:camt.)' ) if not re_camt.search(ns): raise ValueError('no camt: ' + ns) - # Check wether version 052 ,053 or 054: + # Check whether version 052 ,053 or 054: re_camt_version = re.compile( r'(^urn:iso:std:iso:20022:tech:xsd:camt.054.' r'|^urn:iso:std:iso:20022:tech:xsd:camt.053.' diff --git a/account_bank_statement_import_camt/test_files/golden-camt053-txdtls.pydata b/account_bank_statement_import_camt/test_files/golden-camt053-txdtls.pydata index 7d1755f..9b73d97 100644 --- a/account_bank_statement_import_camt/test_files/golden-camt053-txdtls.pydata +++ b/account_bank_statement_import_camt/test_files/golden-camt053-txdtls.pydata @@ -7,12 +7,12 @@ 'transactions': [{'account_number': 'CH2222000000123456789', 'amount': 2187.0, 'date': '2017-03-22', - 'name': u'CR\xc9DIT GROUP\xc9 BVR TRAITEMENT DU 22.03.2017 NUM\xc9RO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', + 'name': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', 'partner_name': 'Banque Cantonale Vaudoise', 'ref': '302388292000011111111111111'}, {'account_number': 'CH3333000000123456789', 'amount': 1296.0, 'date': '2017-03-22', - 'name': u'CR\xc9DIT GROUP\xc9 BVR TRAITEMENT DU 22.03.2017 NUM\xc9RO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', + 'name': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE', 'partner_name': 'Banque Cantonale Vaudoise', 'ref': '302388292000022222222222222'}]}]) diff --git a/account_bank_statement_import_camt/tests/__init__.py b/account_bank_statement_import_camt/tests/__init__.py index 06d3af2..5198b77 100644 --- a/account_bank_statement_import_camt/tests/__init__.py +++ b/account_bank_statement_import_camt/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- encoding: utf-8 -*- """Test import of bank statement for camt.053.""" # © 2013-2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/account_bank_statement_import_camt/tests/test_import_bank_statement.py b/account_bank_statement_import_camt/tests/test_import_bank_statement.py index 840f005..07c2de8 100644 --- a/account_bank_statement_import_camt/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_camt/tests/test_import_bank_statement.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Run test to import camt.053 import.""" # © 2013-2016 Therp BV # Copyright 2017 Open Net Sàrl @@ -8,11 +7,10 @@ import difflib import pprint import tempfile -from odoo.tests.common import TransactionCase -from odoo.tools.misc import file_open - +from io import StringIO -DATA_DIR = 'account_bank_statement_import_camt/test_files/' +from odoo.tests.common import TransactionCase +from odoo.modules.module import get_module_resource class TestParser(TransactionCase): @@ -22,30 +20,41 @@ class TestParser(TransactionCase): self.parser = self.env['account.bank.statement.import.camt.parser'] def _do_parse_test(self, inputfile, goldenfile): - with file_open(inputfile) as testfile: - data = testfile.read() + print("\n\ninputfile = {} / goldenfile = {}".format(inputfile, goldenfile)) + testfile = get_module_resource( + 'account_bank_statement_import_camt', + 'test_files', + inputfile, + ) + data = open(testfile, 'rb').read() res = self.parser.parse(data) - with tempfile.NamedTemporaryFile(suffix='.pydata') as temp: - pprint.pprint(res, temp) - with file_open(goldenfile) as golden: + with tempfile.NamedTemporaryFile(mode='w+', suffix='.pydata') as temp: + import ipdb; ipdb.set_trace(context=10) + pprint.pprint(res, temp, width=160) + goldenfile_res = get_module_resource( + 'account_bank_statement_import_camt', + 'test_files', + goldenfile, + ) + with open(goldenfile_res, 'r') as golden: temp.seek(0) diff = list( difflib.unified_diff(golden.readlines(), temp.readlines(), golden.name, temp.name)) if len(diff) > 2: self.fail( - "actual output doesn't match exptected output:\n%s" % + "actual output doesn't match expected output:\n%s" % "".join(diff)) def test_parse(self): self._do_parse_test( - DATA_DIR + 'test-camt053', - DATA_DIR + 'golden-camt053.pydata') + 'test-camt053', + 'golden-camt053.pydata') def test_parse_txdtls(self): self._do_parse_test( - DATA_DIR + 'test-camt053-txdtls', - DATA_DIR + 'golden-camt053-txdtls.pydata') + 'test-camt053-txdtls', + 'golden-camt053-txdtls.pydata') class TestImport(TransactionCase): @@ -76,11 +85,17 @@ class TestImport(TransactionCase): def test_statement_import(self): """Test correct creation of single statement.""" - action = {} - with file_open(DATA_DIR + 'test-camt053') as testfile: - action = self.env['account.bank.statement.import'].create({ - 'data_file': base64.b64encode(testfile.read()), - }).import_file() + testfile = get_module_resource( + 'account_bank_statement_import_camt', + 'test_files', + 'test-camt053', + ) + datafile = open(testfile, 'rb').read() + + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode(datafile) + }).import_file() + for statement in self.env['account.bank.statement'].browse( action['context']['statement_ids'] ): @@ -96,12 +111,17 @@ class TestImport(TransactionCase): def test_zip_import(self): """Test import of multiple statements from zip file.""" - with file_open( - 'account_bank_statement_import_camt/test_files/test-camt053.zip' - ) as testfile: - action = self.env['account.bank.statement.import'].create({ - 'data_file': base64.b64encode(testfile.read()), - }).import_file() + testfile = get_module_resource( + 'account_bank_statement_import_camt', + 'test_files', + 'test-camt053.zip', + ) + datafile = open(testfile, 'rb').read() + + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode(datafile), + }).import_file() + for statement in self.env['account.bank.statement'].browse( action['context']['statement_ids'] ):