Browse Source

add: module to save the camt ref type when parsing

pull/107/head
Louis Bettens 8 years ago
parent
commit
0439037fa7
  1. 48
      account_bank_statement_import_camt_reftype/README.rst
  2. 4
      account_bank_statement_import_camt_reftype/__init__.py
  3. 14
      account_bank_statement_import_camt_reftype/__openerp__.py
  4. 5
      account_bank_statement_import_camt_reftype/models/__init__.py
  5. 11
      account_bank_statement_import_camt_reftype/models/account_bank_statement_line.py
  6. 22
      account_bank_statement_import_camt_reftype/models/parser.py
  7. 214
      account_bank_statement_import_camt_reftype/test_files/test-camt053-reftype
  8. 4
      account_bank_statement_import_camt_reftype/tests/__init__.py
  9. 42
      account_bank_statement_import_camt_reftype/tests/test_import_bank_statement.py

48
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 <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
------------
* Louis Bettens <lbe@open-net.ch>
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.

4
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

14
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',
],
}

5
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

11
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)

22
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'
)

214
account_bank_statement_import_camt_reftype/test_files/test-camt053-reftype

@ -0,0 +1,214 @@
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.04" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:camt.053.001.04 camt.053.001.04.xsd">
<BkToCstmrStmt>
<GrpHdr>
<MsgId>20170323312345678900000</MsgId>
<CreDtTm>2017-03-23T14:47:00</CreDtTm>
<MsgPgntn>
<PgNb>1</PgNb>
<LastPgInd>true</LastPgInd>
</MsgPgntn>
<AddtlInf>Test</AddtlInf>
</GrpHdr>
<Stmt>
<Id>20170323123456789012345</Id>
<ElctrncSeqNb>58</ElctrncSeqNb>
<CreDtTm>2017-03-23T14:47:00</CreDtTm>
<FrToDt>
<FrDtTm>2017-03-23T00:00:00</FrDtTm>
<ToDtTm>2017-03-23T23:59:59</ToDtTm>
</FrToDt>
<Acct>
<Id>
<IBAN>CH1111000000123456789</IBAN>
</Id>
<Ownr>
<Nm>Open Net S. à r.l. Prilly</Nm>
</Ownr>
</Acct>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>OPBD</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="CHF">75960.15</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2017-03-22</Dt>
</Dt>
</Bal>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>CLBD</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="CHF">79443.15</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2017-03-23</Dt>
</Dt>
</Bal>
<Ntry>
<NtryRef>012345678</NtryRef>
<Amt Ccy="CHF">3483.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<RvslInd>false</RvslInd>
<Sts>BOOK</Sts>
<BookgDt>
<Dt>2017-03-22</Dt>
</BookgDt>
<ValDt>
<Dt>2017-03-23</Dt>
</ValDt>
<AcctSvcrRef>20170323001234567891234567891234</AcctSvcrRef>
<BkTxCd>
<Domn>
<Cd>PMNT</Cd>
<Fmly>
<Cd>RCDT</Cd>
<SubFmlyCd>VCOM</SubFmlyCd>
</Fmly>
</Domn>
</BkTxCd>
<NtryDtls>
<Btch>
<NbOfTxs>2</NbOfTxs>
</Btch>
<TxDtls>
<Refs>
<AcctSvcrRef>123456CHCAFEBABE</AcctSvcrRef>
<Prtry>
<Tp>01</Tp>
<Ref>123456CHCAFEBABE</Ref>
</Prtry>
</Refs>
<Amt Ccy="CHF">2187.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<BkTxCd>
<Domn>
<Cd>PMNT</Cd>
<Fmly>
<Cd>RCDT</Cd>
<SubFmlyCd>AUTT</SubFmlyCd>
</Fmly>
</Domn>
</BkTxCd>
<RltdPties>
<Dbtr>
<Nm>Banque Cantonale Vaudoise</Nm>
<PstlAdr>
<StrtNm>Place Saint-François</StrtNm>
<BldgNb>14</BldgNb>
<PstCd>1003</PstCd>
<TwnNm>Lausanne</TwnNm>
<Ctry>CH1</Ctry>
</PstlAdr>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>CH2222000000123456789</IBAN>
</Id>
</DbtrAcct>
</RltdPties>
<RltdAgts>
<DbtrAgt>
<FinInstnId>
<BICFI>POFICHBEXXX</BICFI>
<Nm>POSTFINANCE AG</Nm>
<PstlAdr>
<AdrLine>MINGERSTRASSE 20</AdrLine>
<AdrLine>3030 BERNE</AdrLine>
</PstlAdr>
</FinInstnId>
</DbtrAgt>
</RltdAgts>
<RmtInf>
<Strd>
<CdtrRefInf>
<Tp>
<CdOrPrtry>
<Prtry>ISR Reference</Prtry>
</CdOrPrtry>
</Tp>
<Ref>302388292000011111111111111</Ref>
</CdtrRefInf>
<AddtlRmtInf>?REJECT?0</AddtlRmtInf>
</Strd>
</RmtInf>
<RltdDts>
<AccptncDtTm>2017-03-22T20:00:00</AccptncDtTm>
</RltdDts>
</TxDtls>
<TxDtls>
<Refs>
<AcctSvcrRef>123456CHCAFEBABE</AcctSvcrRef>
<Prtry>
<Tp>01</Tp>
<Ref>123456CHCAFEBABE</Ref>
</Prtry>
</Refs>
<Amt Ccy="CHF">1296.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<BkTxCd>
<Domn>
<Cd>PMNT</Cd>
<Fmly>
<Cd>RCDT</Cd>
<SubFmlyCd>AUTT</SubFmlyCd>
</Fmly>
</Domn>
</BkTxCd>
<RltdPties>
<Dbtr>
<Nm>Banque Cantonale Vaudoise</Nm>
<PstlAdr>
<StrtNm>Place Saint-François</StrtNm>
<BldgNb>14</BldgNb>
<PstCd>1003</PstCd>
<TwnNm>Lausanne</TwnNm>
<Ctry>CH2</Ctry>
</PstlAdr>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>CH3333000000123456789</IBAN>
</Id>
</DbtrAcct>
</RltdPties>
<RltdAgts>
<DbtrAgt>
<FinInstnId>
<BICFI>POFICHBEYYY</BICFI>
<Nm>POSTFINANCE AG</Nm>
<PstlAdr>
<AdrLine>MINGERSTRASSE 20</AdrLine>
<AdrLine>3030 BERNE</AdrLine>
</PstlAdr>
</FinInstnId>
</DbtrAgt>
</RltdAgts>
<RmtInf>
<Strd>
<CdtrRefInf>
<Tp>
<CdOrPrtry>
<Prtry>ISR Reference</Prtry>
</CdOrPrtry>
</Tp>
<Ref>302388292000022222222222222</Ref>
</CdtrRefInf>
<AddtlRmtInf>?REJECT?0</AddtlRmtInf>
</Strd>
</RmtInf>
<RltdDts>
<AccptncDtTm>2017-03-22T20:00:00</AccptncDtTm>
</RltdDts>
</TxDtls>
</NtryDtls>
<AddtlNtryInf>CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE</AddtlNtryInf>
</Ntry>
</Stmt>
</BkToCstmrStmt>
</Document>

4
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

42
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")
Loading…
Cancel
Save