From 0439037fa7c59de26fdc34db497809d919382a3a Mon Sep 17 00:00:00 2001 From: Louis Bettens Date: Thu, 20 Apr 2017 14:23:17 +0200 Subject: [PATCH] add: module to save the camt ref type when parsing --- .../README.rst | 48 ++++ .../__init__.py | 4 + .../__openerp__.py | 14 ++ .../models/__init__.py | 5 + .../models/account_bank_statement_line.py | 11 + .../models/parser.py | 22 ++ .../test_files/test-camt053-reftype | 214 ++++++++++++++++++ .../tests/__init__.py | 4 + .../tests/test_import_bank_statement.py | 42 ++++ 9 files changed, 364 insertions(+) create mode 100644 account_bank_statement_import_camt_reftype/README.rst create mode 100644 account_bank_statement_import_camt_reftype/__init__.py create mode 100644 account_bank_statement_import_camt_reftype/__openerp__.py create mode 100644 account_bank_statement_import_camt_reftype/models/__init__.py create mode 100644 account_bank_statement_import_camt_reftype/models/account_bank_statement_line.py create mode 100644 account_bank_statement_import_camt_reftype/models/parser.py create mode 100644 account_bank_statement_import_camt_reftype/test_files/test-camt053-reftype create mode 100644 account_bank_statement_import_camt_reftype/tests/__init__.py create mode 100644 account_bank_statement_import_camt_reftype/tests/test_import_bank_statement.py diff --git a/account_bank_statement_import_camt_reftype/README.rst b/account_bank_statement_import_camt_reftype/README.rst new file mode 100644 index 0000000..96c1ba6 --- /dev/null +++ b/account_bank_statement_import_camt_reftype/README.rst @@ -0,0 +1,48 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Bank Statement Parse Camt Reference Type +======================================== + +Module to add reference information in bank statement lines from SEPA CAMT.053 Format bank statement files. + +Based on the Banking addons framework. + +Known issues / Roadmap +====================== + +* 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 `_. + + +Credits +======= + +Contributors +------------ + +* Louis Bettens + +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. diff --git a/account_bank_statement_import_camt_reftype/__init__.py b/account_bank_statement_import_camt_reftype/__init__.py new file mode 100644 index 0000000..a1e9b9d --- /dev/null +++ b/account_bank_statement_import_camt_reftype/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/account_bank_statement_import_camt_reftype/__openerp__.py b/account_bank_statement_import_camt_reftype/__openerp__.py new file mode 100644 index 0000000..3cada5b --- /dev/null +++ b/account_bank_statement_import_camt_reftype/__openerp__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'CAMT Reference Type Bank Statements Import', + 'version': '9.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Odoo Community Association (OCA), Open Net Sàrl', + 'website': 'https://github.com/OCA/bank-statement-import', + 'category': 'Banking addons', + 'depends': [ + 'account_bank_statement_import_camt', + ], +} diff --git a/account_bank_statement_import_camt_reftype/models/__init__.py b/account_bank_statement_import_camt_reftype/models/__init__.py new file mode 100644 index 0000000..89daf53 --- /dev/null +++ b/account_bank_statement_import_camt_reftype/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import account_bank_statement_line +from . import parser diff --git a/account_bank_statement_import_camt_reftype/models/account_bank_statement_line.py b/account_bank_statement_import_camt_reftype/models/account_bank_statement_line.py new file mode 100644 index 0000000..411b238 --- /dev/null +++ b/account_bank_statement_import_camt_reftype/models/account_bank_statement_line.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models + + +class AccountBankStatementLine(models.Model): + _inherit = 'account.bank.statement.line' + + camt_ref_type = fields.Char(string='Type of reference', max=35) diff --git a/account_bank_statement_import_camt_reftype/models/parser.py b/account_bank_statement_import_camt_reftype/models/parser.py new file mode 100644 index 0000000..7b9bc41 --- /dev/null +++ b/account_bank_statement_import_camt_reftype/models/parser.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models + + +class CamtReftypeParser(models.AbstractModel): + """Parser for camt bank statement import files.""" + _inherit = 'account.bank.statement.import.camt.parser' + + def parse_transaction_details(self, ns, node, transaction): + super(CamtReftypeParser, self).parse_transaction_details( + ns, node, transaction) + + self.add_value_from_node( + ns, node, [ + './ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Tp/ns:CdOrPrtry/' + 'ns:Prtry', + ], + transaction, 'camt_ref_type' + ) diff --git a/account_bank_statement_import_camt_reftype/test_files/test-camt053-reftype b/account_bank_statement_import_camt_reftype/test_files/test-camt053-reftype new file mode 100644 index 0000000..cf7c38f --- /dev/null +++ b/account_bank_statement_import_camt_reftype/test_files/test-camt053-reftype @@ -0,0 +1,214 @@ + + + + + 20170323312345678900000 + 2017-03-23T14:47:00 + + 1 + true + + Test + + + 20170323123456789012345 + 58 + 2017-03-23T14:47:00 + + 2017-03-23T00:00:00 + 2017-03-23T23:59:59 + + + + CH1111000000123456789 + + + Open Net S. à r.l. Prilly + + + + + + OPBD + + + 75960.15 + CRDT +
+
2017-03-22
+ +
+ + + + CLBD + + + 79443.15 + CRDT +
+
2017-03-23
+ +
+ + 012345678 + 3483.00 + CRDT + false + BOOK + +
2017-03-22
+
+ +
2017-03-23
+
+ 20170323001234567891234567891234 + + + PMNT + + RCDT + VCOM + + + + + + 2 + + + + 123456CHCAFEBABE + + 01 + 123456CHCAFEBABE + + + 2187.00 + CRDT + + + PMNT + + RCDT + AUTT + + + + + + Banque Cantonale Vaudoise + + Place Saint-François + 14 + 1003 + Lausanne + CH1 + + + + + CH2222000000123456789 + + + + + + + POFICHBEXXX + POSTFINANCE AG + + MINGERSTRASSE 20 + 3030 BERNE + + + + + + + + + + ISR Reference + + + 302388292000011111111111111 + + ?REJECT?0 + + + + 2017-03-22T20:00:00 + + + + + 123456CHCAFEBABE + + 01 + 123456CHCAFEBABE + + + 1296.00 + CRDT + + + PMNT + + RCDT + AUTT + + + + + + Banque Cantonale Vaudoise + + Place Saint-François + 14 + 1003 + Lausanne + CH2 + + + + + CH3333000000123456789 + + + + + + + POFICHBEYYY + POSTFINANCE AG + + MINGERSTRASSE 20 + 3030 BERNE + + + + + + + + + + ISR Reference + + + 302388292000022222222222222 + + ?REJECT?0 + + + + 2017-03-22T20:00:00 + + + + CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE +
+
+
+
diff --git a/account_bank_statement_import_camt_reftype/tests/__init__.py b/account_bank_statement_import_camt_reftype/tests/__init__.py new file mode 100644 index 0000000..6948394 --- /dev/null +++ b/account_bank_statement_import_camt_reftype/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- encoding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_import_bank_statement diff --git a/account_bank_statement_import_camt_reftype/tests/test_import_bank_statement.py b/account_bank_statement_import_camt_reftype/tests/test_import_bank_statement.py new file mode 100644 index 0000000..e18db95 --- /dev/null +++ b/account_bank_statement_import_camt_reftype/tests/test_import_bank_statement.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Open Net Sàrl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import base64 + +from openerp.tests.common import TransactionCase +from openerp.tools.misc import file_open + + +DATA_DIR = 'account_bank_statement_import_camt_reftype/test_files/' + + +class TestImport(TransactionCase): + """Run test to import camt import.""" + + def setUp(self): + super(TestImport, self).setUp() + bank = self.env['res.partner.bank'].create({ + 'acc_number': 'CH1111000000123456789', + 'partner_id': self.env.ref('base.main_partner').id, + 'company_id': self.env.ref('base.main_company').id, + 'bank_id': self.env.ref('base.res_bank_1').id, + }) + self.env['account.journal'].create({ + 'name': 'Bank Journal - (test camt)', + 'code': 'TBNKCAMT', + 'type': 'bank', + 'bank_account_id': bank.id, + }) + + def test_statement_import(self): + """Test that reference type is correctly imported.""" + with file_open(DATA_DIR + 'test-camt053-reftype') as testfile: + data = testfile.read() + action = self.env['account.bank.statement.import'].create({ + 'data_file': base64.b64encode(data) + }).import_file() + statements = self.env['account.bank.statement'].browse( + action['context']['statement_ids'] + ) + for line in statements.mapped('line_ids'): + self.assertEqual(line.camt_ref_type, "ISR Reference")