Browse Source
Merge pull request #79 from hbrunn/9.0-account_bank_statement_import_camt
Merge pull request #79 from hbrunn/9.0-account_bank_statement_import_camt
9.0 account bank statement import camtpull/82/head
Pedro M. Baeza
8 years ago
committed by
GitHub
15 changed files with 253 additions and 208 deletions
-
1account_bank_statement_import_camt/README.rst
-
6account_bank_statement_import_camt/__init__.py
-
26account_bank_statement_import_camt/__openerp__.py
-
44account_bank_statement_import_camt/account_bank_statement_import.py
-
102account_bank_statement_import_camt/camt.py
-
29account_bank_statement_import_camt/demo/demo_data.xml
-
24account_bank_statement_import_camt/i18n/de.po
-
23account_bank_statement_import_camt/i18n/pt_PT.po
-
4account_bank_statement_import_camt/models/__init__.py
-
42account_bank_statement_import_camt/models/account_bank_statement_import.py
-
30account_bank_statement_import_camt/test_files/test-camt053
-
BINaccount_bank_statement_import_camt/test_files/test-camt053.zip
-
22account_bank_statement_import_camt/tests/__init__.py
-
79account_bank_statement_import_camt/tests/test_import_bank_statement.py
-
15account_bank_statement_import_camt/views/account_bank_statement_import.xml
@ -1 +1,5 @@ |
|||
from . import account_bank_statement_import |
|||
# -*- coding: utf-8 -*- |
|||
# © 2013-2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import models |
|||
from . import camt |
@ -1,44 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
"""Add process_camt method to account.bank.statement.import.""" |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2013-2015 Therp BV <http://therp.nl> |
|||
# |
|||
# 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 logging |
|||
from openerp import models |
|||
from .camt import CamtParser as Parser |
|||
|
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class AccountBankStatementImport(models.TransientModel): |
|||
"""Add process_camt method to account.bank.statement.import.""" |
|||
_inherit = 'account.bank.statement.import' |
|||
|
|||
def _parse_file(self, cr, uid, data_file, context=None): |
|||
"""Parse a CAMT053 XML file.""" |
|||
parser = Parser() |
|||
try: |
|||
_logger.debug("Try parsing with camt.") |
|||
return parser.parse(data_file) |
|||
except ValueError: |
|||
# Not a camt file, returning super will call next candidate: |
|||
_logger.debug("Statement file was not a camt file.", |
|||
exc_info=True) |
|||
return super(AccountBankStatementImport, self)._parse_file( |
|||
cr, uid, data_file, context=context) |
@ -1,26 +1,15 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<odoo> |
|||
<record id="camt_company_bank" model="res.partner.bank"> |
|||
<field name="acc_number">NL77ABNA0574908765</field> |
|||
<field name="partner_id" ref="base.main_partner"></field> |
|||
<field name="company_id" ref="base.main_company"></field> |
|||
<field name="bank_id" ref="base.res_bank_1"/> |
|||
</record> |
|||
<record id="camt_bank_journal" model="account.journal"> |
|||
<field name="name">Bank Journal - (test camt)</field> |
|||
<field name="code">TBNKCAMT</field> |
|||
<field name="type">bank</field> |
|||
<field name="sequence_id" ref="account.sequence_bank_journal"/> |
|||
<field name="default_debit_account_id" ref="account.bnk"/> |
|||
<field name="default_credit_account_id" ref="account.bnk"/> |
|||
<field name="user_id" ref="base.user_root"/> |
|||
</record> |
|||
|
|||
<record id="camt_company_bank" model="res.partner.bank"> |
|||
<field name="owner_name">Your Company</field> |
|||
<field name="acc_number">NL77ABNA0574908765</field> |
|||
<field name="partner_id" ref="base.partner_root"></field> |
|||
<field name="company_id" ref="base.main_company"></field> |
|||
<field name="journal_id" ref="camt_bank_journal"></field> |
|||
<field name="state">bank</field> |
|||
<field name="bank" ref="base.res_bank_1"/> |
|||
<field name="bank_account_id" ref="camt_company_bank" /> |
|||
</record> |
|||
</data> |
|||
|
|||
</openerp> |
|||
</odoo> |
@ -0,0 +1,24 @@ |
|||
# Translation of Odoo Server. |
|||
# This file contains the translation of the following modules: |
|||
# * account_bank_statement_import_camt |
|||
# |
|||
# Translators: |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: bank-statement-import (8.0)\n" |
|||
"Report-Msgid-Bugs-To: \n" |
|||
"POT-Creation-Date: 2015-07-24 21:51+0000\n" |
|||
"PO-Revision-Date: 2015-10-04 11:43+0200\n" |
|||
"Last-Translator: Rudolf Schnapka <rs@techno-flex.de>\n" |
|||
"Language-Team: French (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/fr/)\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: 8bit\n" |
|||
"Language: fr\n" |
|||
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|||
"X-Generator: Poedit 1.8.3\n" |
|||
|
|||
#. module: account_bank_statement_import_camt |
|||
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import |
|||
msgid "Import Bank Statement" |
|||
msgstr "Kontoauszug importieren" |
@ -0,0 +1,23 @@ |
|||
# Translation of Odoo Server. |
|||
# This file contains the translation of the following modules: |
|||
# * account_bank_statement_import_camt |
|||
# |
|||
# Translators: |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: bank-statement-import (8.0)\n" |
|||
"Report-Msgid-Bugs-To: \n" |
|||
"POT-Creation-Date: 2016-08-18 10:27+0000\n" |
|||
"PO-Revision-Date: 2015-07-24 07:41+0000\n" |
|||
"Last-Translator: <>\n" |
|||
"Language-Team: Portuguese (Portugal) (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/pt_PT/)\n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: \n" |
|||
"Language: pt_PT\n" |
|||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" |
|||
|
|||
#. module: account_bank_statement_import_camt |
|||
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import |
|||
msgid "Import Bank Statement" |
|||
msgstr "Importar Extrato Bancário" |
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2013-2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import account_bank_statement_import |
@ -0,0 +1,42 @@ |
|||
# -*- coding: utf-8 -*- |
|||
"""Add process_camt method to account.bank.statement.import.""" |
|||
# © 2013-2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
import logging |
|||
import StringIO |
|||
import zipfile |
|||
from openerp import api, models |
|||
from ..camt import CamtParser as Parser |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class AccountBankStatementImport(models.TransientModel): |
|||
"""Add process_camt method to account.bank.statement.import.""" |
|||
_inherit = 'account.bank.statement.import' |
|||
|
|||
@api.model |
|||
def _parse_file(self, data_file): |
|||
"""Parse a CAMT053 XML file.""" |
|||
try: |
|||
parser = Parser() |
|||
_logger.debug("Try parsing with camt.") |
|||
return parser.parse(data_file) |
|||
except ValueError: |
|||
try: |
|||
with zipfile.ZipFile(StringIO.StringIO(data_file)) as data: |
|||
currency = None |
|||
account_number = None |
|||
transactions = [] |
|||
for member in data.namelist(): |
|||
currency, account_number, new = self._parse_file( |
|||
data.open(member).read() |
|||
) |
|||
transactions.extend(new) |
|||
return currency, account_number, transactions |
|||
except (zipfile.BadZipfile, ValueError): |
|||
pass |
|||
# Not a camt file, returning super will call next candidate: |
|||
_logger.debug("Statement file was not a camt file.", |
|||
exc_info=True) |
|||
return super(AccountBankStatementImport, self)._parse_file(data_file) |
@ -1,23 +1,5 @@ |
|||
# -*- encoding: utf-8 -*- |
|||
"""Test import of bank statement for camt.053.""" |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# All other contributions are (C) by their respective contributors |
|||
# |
|||
# 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/>. |
|||
# |
|||
############################################################################## |
|||
# © 2013-2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import test_import_bank_statement |
@ -1,45 +1,54 @@ |
|||
# -*- coding: utf-8 -*- |
|||
"""Run test to import camt.053 import.""" |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# 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/>. |
|||
# |
|||
############################################################################## |
|||
from openerp.addons.account_bank_statement_import.tests import ( |
|||
TestStatementFile) |
|||
# © 2013-2016 Therp BV <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(TestStatementFile): |
|||
class TestImport(TransactionCase): |
|||
"""Run test to import camt import.""" |
|||
|
|||
def test_statement_import(self): |
|||
"""Test correct creation of single statement.""" |
|||
transactions = [ |
|||
{ |
|||
'remote_account': 'NL46ABNA0499998748', |
|||
'transferred_amount': -754.25, |
|||
'value_date': '2013-01-05', |
|||
'account_number': 'NL46ABNA0499998748', |
|||
'amount': -754.25, |
|||
'date': '2014-01-05', |
|||
'ref': '435005714488-ABNO33052620', |
|||
}, |
|||
] |
|||
# statement name is account number + '-' + date of last 62F line: |
|||
self._test_statement_import( |
|||
'account_bank_statement_import_camt', 'test-camt053.xml', |
|||
'1234Test/1', |
|||
local_account='NL77ABNA0574908765', |
|||
start_balance=15568.27, end_balance=15121.12, |
|||
transactions=transactions |
|||
) |
|||
|
|||
def test_statement_import(self): |
|||
"""Test correct creation of single statement.""" |
|||
action = {} |
|||
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() |
|||
for statement in self.env['account.bank.statement'].browse( |
|||
action['context']['statement_ids'] |
|||
): |
|||
self.assertTrue(any( |
|||
all( |
|||
line[key] == self.transactions[0][key] |
|||
for key in ['amount', 'date', 'ref'] |
|||
) and |
|||
line.bank_account_id.acc_number == |
|||
self.transactions[0]['account_number'] |
|||
for line in statement.line_ids |
|||
)) |
|||
|
|||
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() |
|||
for statement in self.env['account.bank.statement'].browse( |
|||
action['context']['statement_ids'] |
|||
): |
|||
self.assertTrue(statement.line_ids) |
@ -0,0 +1,15 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
<record id="account_bank_statement_import_view" model="ir.ui.view"> |
|||
<field name="model">account.bank.statement.import</field> |
|||
<field name="inherit_id" ref="account_bank_statement_import.account_bank_statement_import_view" /> |
|||
<field name="arch" type="xml"> |
|||
<ul id="statement_format" position="inside"> |
|||
<li>CAMT</li> |
|||
<li>zipped CAMT</li> |
|||
</ul> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue