Skip to content

Commit

Permalink
[ADD] camt_details bank statement import
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed May 5, 2017
1 parent 892ba48 commit fd0e3e6
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 0 deletions.
48 changes: 48 additions & 0 deletions account_bank_statement_import_camt_details/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 Debitor Details
=========================================

Module to add debitor details 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
------------

* Emanuel Cino <ecino@compassion.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.
5 changes: 5 additions & 0 deletions account_bank_statement_import_camt_details/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from . import camt
20 changes: 20 additions & 0 deletions account_bank_statement_import_camt_details/__openerp__.py
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'CAMT Debitor Details Bank Statements Import',
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'author': 'Odoo Community Association (OCA), Compassion CH',
'website': 'https://github.com/OCA/bank-statement-import',
'category': 'Banking addons',
'depends': [
'account_bank_statement_import_camt',
],
'data': [
'views/account_bank_statement_line.xml',
],
'qweb': [
'static/src/xml/camt_details_reconciliation_layout.xml',
]
}
47 changes: 47 additions & 0 deletions account_bank_statement_import_camt_details/camt.py
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
"""Class to parse camt files."""
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.addons.account_bank_statement_import_camt.camt import CamtParser


class CamtDetailsParser(CamtParser):
"""Parser for camt bank statement import files."""

def parse_transaction_details(self, ns, node, transaction):
"""Parse transaction details (message, party, account...)."""
super(CamtDetailsParser, self).parse_transaction_details(
ns, node, transaction)

# remote party values
party_type = 'Dbtr'
party_type_node = node.xpath(
'../../ns:CdtDbtInd', namespaces={'ns': ns})
if party_type_node and party_type_node[0].text != 'CRDT':
party_type = 'Cdtr'
address_node = node.xpath(
'./ns:RltdPties/ns:%s/ns:PstlAdr' % party_type,
namespaces={'ns': ns})
if address_node and not transaction.get('partner_address'):
address_values = list()
street_node = address_node[0].xpath(
'./ns:StrtNm', namespaces={'ns': ns})
if street_node:
address_values.append(street_node[0].text)
building_node = address_node[0].xpath(
'./ns:BldgNb', namespaces={'ns': ns})
if building_node:
address_values.append(building_node[0].text)
zip_node = address_node[0].xpath(
'./ns:PstCd', namespaces={'ns': ns})
if zip_node:
address_values.append(zip_node[0].text)
city_node = address_node[0].xpath(
'./ns:TwnNm', namespaces={'ns': ns})
if city_node:
address_values.append(city_node[0].text)
transaction['partner_address'] = ', '.join(address_values)

# Transfer account info in fields
transaction['partner_account'] = transaction.get('account_number')
transaction['partner_bic'] = transaction.get('account_bic')
5 changes: 5 additions & 0 deletions account_bank_statement_import_camt_details/models/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import account_bank_statement_import
from . import account_bank_statement_line
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""Add process_camt method to account.bank.statement.import."""
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, models
from ..camt import CamtDetailsParser as Parser


class AccountBankStatementImport(models.TransientModel):
"""Add process_camt method to account.bank.statement.import."""
_inherit = 'account.bank.statement.import'

@api.model
def _get_camt_parser_mixins(self, bases):
bases.append(Parser)
super(AccountBankStatementImport, self)._get_camt_parser_mixins(bases)
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""Add process_camt method to account.bank.statement.import."""
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields


class AccountBankStatementLine(models.TransientModel):
"""Add process_camt method to account.bank.statement.import."""
_inherit = 'account.bank.statement.line'

partner_address = fields.Char()
partner_account = fields.Char()
partner_bic = fields.Char()

def get_statement_line_for_reconciliation_widget(self):
""" Returns the data required by the bank statement
reconciliation widget to display a statement line
"""
data = super(AccountBankStatementLine,
self).get_statement_line_for_reconciliation_widget()
if self.partner_address:
data['partner_address'] = self.partner_address
if self.partner_account:
data['partner_account'] = self.partner_account

return data
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates id="template" xml:space="preserve">
<t t-extend="bank_statement_reconciliation_statement_line_details">

<t t-jquery="table.details > tr:nth-child(2)" t-operation="after">
<tr t-if="line.partner_address"><td>Address</td><td><t t-esc="line.partner_address"/></td></tr>
</t>
<t t-jquery="table.details > tr:nth-child(6)" t-operation="after">
<tr t-if="line.partner_account"><td>Partner account</td><td><t t-esc="line.partner_account"/></td></tr>
</t>
</t>
</templates>
5 changes: 5 additions & 0 deletions account_bank_statement_import_camt_details/tests/__init__.py
@@ -0,0 +1,5 @@
# -*- encoding: utf-8 -*-
"""Test import of bank statement for camt.053."""
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_import_bank_statement
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
# © 2017 CompassionCH <http://therp.nl>
# 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


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': 'NL77ABNA0574908765',
'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 transaction details are correctly imported."""
line_details = [
{
'partner_account': 'NL46ABNA0499998748',
'partner_bic': 'ABNANL2A',
'partner_name': 'INSURANCE COMPANY TESTX',
'partner_address': 'TEST STREET 20, 1234 AB TESTCITY'
},
{
'partner_account': 'NL46ABNA0499998748',
'partner_bic': 'ABNANL2A',
'partner_name': 'Test Customer',
},
{
'partner_account': 'NL69ABNA0522123643',
'partner_bic': 'ABNANL2A',
'partner_name': '3rd party Media',
'partner_address': 'SOMESTREET 570-A, 1276 ML HOUSCITY'
},
]
with file_open(
'account_bank_statement_import_camt/test_files/test-camt053'
) as testfile:
action = self.env['account.bank.statement.import'].create({
'data_file': base64.b64encode(testfile.read()),
}).import_file()
statement_lines = self.env['account.bank.statement'].browse(
action['context']['statement_ids']).mapped('line_ids')
for i in range(0, len(line_details)):
for key, val in line_details[i].iteritems():
self.assertEqual(getattr(statement_lines[i], key), val)
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="statement_line_details" model="ir.ui.view">
<field name="name">bank.statement.line.details</field>
<field name="model">account.bank.statement.line</field>
<field name="type">form</field>
<field name="inherit_id" ref="account.view_bank_statement_line_form" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="partner_name"/>
<field name="partner_account"/>
<field name="partner_address"/>
<field name="partner_bic"/>
</field>
</field>
</record>
</odoo>

0 comments on commit fd0e3e6

Please sign in to comment.