From 3ea97a18c107bbb576f56df2c7d06c9c360fa558 Mon Sep 17 00:00:00 2001 From: Rudolf Schnapka Date: Sun, 4 Oct 2015 11:57:58 +0200 Subject: [PATCH 1/9] german translations for bank-statement-import --- account_bank_statement_import_camt/i18n/de.po | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 account_bank_statement_import_camt/i18n/de.po diff --git a/account_bank_statement_import_camt/i18n/de.po b/account_bank_statement_import_camt/i18n/de.po new file mode 100644 index 0000000..b503264 --- /dev/null +++ b/account_bank_statement_import_camt/i18n/de.po @@ -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 \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" From 87718b4eb9aa8504866c9212f72e95ea6b2a1cac Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Fri, 9 Oct 2015 15:08:42 +0200 Subject: [PATCH 2/9] Make sure message is filled for camt. Message was not taken from AddtlNtryInf element, if not part of details. Not sure wether it actually can be part of details (NtryDtls element), but this change least intrusive. --- account_bank_statement_import_camt/camt.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_bank_statement_import_camt/camt.py b/account_bank_statement_import_camt/camt.py index 81fd1de..96e7a51 100644 --- a/account_bank_statement_import_camt/camt.py +++ b/account_bank_statement_import_camt/camt.py @@ -134,6 +134,9 @@ class CamtParser(object): './ns:NtryDtls/ns:TxDtls', namespaces={'ns': ns}) if details_node: self.parse_transaction_details(ns, details_node[0], transaction) + if not transaction.message: + self.add_value_from_node( + ns, node, './ns:AddtlNtryInf', transaction, 'message') transaction.data = etree.tostring(node) return transaction From d279bd2d69e96ee99929e73b042d47ed13e35076 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Sat, 13 Jun 2015 01:20:18 +0200 Subject: [PATCH 3/9] Support zip files. --- .../__manifest__.py | 2 +- account_bank_statement_import_camt/camt.py | 9 +++++- .../test_files/test-camt053.xml | 30 +++++++++--------- .../test_files/test-camt053.zip | Bin 0 -> 3111 bytes .../tests/test_import_bank_statement.py | 11 +++++-- 5 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 account_bank_statement_import_camt/test_files/test-camt053.zip diff --git a/account_bank_statement_import_camt/__manifest__.py b/account_bank_statement_import_camt/__manifest__.py index a59c096..86ce0c5 100644 --- a/account_bank_statement_import_camt/__manifest__.py +++ b/account_bank_statement_import_camt/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'CAMT Format Bank Statements Import', - 'version': '8.0.0.3.0', + 'version': '8.0.0.4.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/camt.py b/account_bank_statement_import_camt/camt.py index 96e7a51..aed01db 100644 --- a/account_bank_statement_import_camt/camt.py +++ b/account_bank_statement_import_camt/camt.py @@ -69,7 +69,7 @@ class CamtParser(object): './ns:RmtInf/ns:Ustrd', './ns:AddtlTxInf', './ns:AddtlNtryInf', - ], transaction, 'message') + ], transaction, 'message', join_str='\n') # eref self.add_value_from_node( ns, node, [ @@ -137,6 +137,13 @@ class CamtParser(object): if not transaction.message: self.add_value_from_node( ns, node, './ns:AddtlNtryInf', transaction, 'message') + if not transaction.eref: + self.add_value_from_node( + ns, node, [ + './ns:NtryDtls/ns:Btch/ns:PmtInfId', + ], + transaction, 'eref' + ) transaction.data = etree.tostring(node) return transaction diff --git a/account_bank_statement_import_camt/test_files/test-camt053.xml b/account_bank_statement_import_camt/test_files/test-camt053.xml index 1d74d81..4a2a047 100644 --- a/account_bank_statement_import_camt/test_files/test-camt053.xml +++ b/account_bank_statement_import_camt/test_files/test-camt053.xml @@ -2,15 +2,15 @@ TESTBANK/NL/1420561226673 - 2013-01-06T16:20:26.673Z + 2014-01-06T16:20:26.673Z 1234Test/1 2 - 2013-01-06T16:20:26.673Z + 2014-01-06T16:20:26.673Z - 2013-01-05T00:00:00.000Z - 2013-01-05T23:59:59.999Z + 2014-01-05T00:00:00.000Z + 2014-01-05T23:59:59.999Z @@ -32,7 +32,7 @@ 15568.27 CRDT
-
2013-01-05
+
2014-01-05
@@ -44,7 +44,7 @@ 15121.12 CRDT
-
2013-01-05
+
2014-01-05
@@ -52,10 +52,10 @@ DBIT BOOK -
2013-01-05
+
2014-01-05
-
2013-01-05
+
2014-01-05
@@ -104,9 +104,9 @@ - Insurance policy 857239PERIOD 01.01.2013 - 31.12.2013 + Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014 - MKB Insurance 859239PERIOD 01.01.2013 - 31.12.2013 + MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014
@@ -116,10 +116,10 @@ true BOOK -
2013-01-05
+
2014-01-05
-
2013-01-05
+
2014-01-05
@@ -182,10 +182,10 @@ CRDT BOOK -
2013-01-05
+
2014-01-05
-
2013-01-05
+
2014-01-05
@@ -202,7 +202,7 @@ - INNDNL2U20130105000217200000708 + INNDNL2U20140105000217200000708 115 diff --git a/account_bank_statement_import_camt/test_files/test-camt053.zip b/account_bank_statement_import_camt/test_files/test-camt053.zip new file mode 100644 index 0000000000000000000000000000000000000000..ccf5b3c2ba72ad03cc137edcf2ee55f67b7a2952 GIT binary patch literal 3111 zcmeH}=T{S08pZ=5FccF7R764P14xk;5EP_{0RmY=5O4w{AVr!$C=oHlAWJhyReBE! zAqJ!U#$s;Q+O;qQmC7X$#CFp;S53XKp3 z@bIyK0Kng`kJ*<4=k&#UW|xqT(@Tov5YUyorl#QtnL>GL823Dkl9(M6fc0cI%(|Ni z6Q^GLcu71wsM2}%?CvjH!8b!s<&9$V%#|&29fp7$*Z6H3|gs9r@Iab`}w zn70^AGxt!43sw21&ugEeu5!s zB=aSvS|O$Bs(_1W`3N!7kW{?C+9uvd?a-AuvRv(>X!goeIdlV;b{mCeyP1vK$0=9p zhvGziT|Owbw0q_obsli0rv4Sr^-c(wMC`04QcZhDwWKHp@XFHQlHEbhsWMKSBZZOw zA}>C4#%A3WrP-sj`HDO4lA-;!yrBVX&3%#eOMKMU@+IV(nv7lhYS%{;$3{6@D@-?8 zj%$0W-f~sSJ^sQi^P9;MO$$IZFznJn;)6b5Ft;O?XIp3Wvr?Mxgx4Co_F1d*^z6>W z16A~WLf`!H5cIp~GA4ZCR{`G`WEw$zws*gec}$;&fZM zo5o5(B`9uG=!A2Ina*WDMms&g&>^6!qHt5;GqTVR1>*Ec+Z)I*wlOs-1v{7k(SD7cx&3TX>4UUU|z4aL*H}d*MEMlY`)`QpML{Lh>UZ>Y$ z#RRHb?tB{p^?Uws=MQd|l>2$Th%nhp47tF`Rx7B!RoxbGo{x9Ijt)~YQ+V444% zPzs&KG$xTJ)T2(Qz^8|QRB}mXgGS2uVz8>+^ZoN75^~j6MqhVW51<$wUzWDyF|J1 zirME@jT#|^OHAAz3aV0H+~Jxv^`tk-VY6f-Rl*g=@Y-F-Ba{e9gU80nOv-XmG14&C zV(E)5%on5Y=I7h_Gab0duA42{ST}8V<9on@o5adK;Lj4$TmL;iTZRlaNcE zF1&6LTv;hka~iWF8};~H>r~tMthOl-2An0f&eCUPY+h! z>c3ZOHlMoCRY`(}DnQqY19eBIViuA`HhKm_r5I4{dR+8rdB$SfS*>Oa_D7-8&b&W) z{U@*guX)YGD-Hakf-SLEya527J(Uu_PrqBYLI0@RzhO7R`d`NX9R>ex{Ae#A{?quM b!LVoiJE4HE2JwIY3-8{k*?V1uzi)p7q~E=A literal 0 HcmV?d00001 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 8a1694f..d14aca9 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 @@ -31,11 +31,10 @@ class TestImport(TestStatementFile): { 'remote_account': 'NL46ABNA0499998748', 'transferred_amount': -754.25, - 'value_date': '2013-01-05', + 'value_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', @@ -43,3 +42,11 @@ class TestImport(TestStatementFile): start_balance=15568.27, end_balance=15121.12, transactions=transactions ) + + def test_zip_import(self): + """Test import of multiple statements from zip file.""" + self._test_statement_import( + 'account_bank_statement_import_camt', 'test-camt053.zip', + '1234Test/2', # Only name of first statement + local_account='NL77ABNA0574908765', + ) From 520cc926c8c879df23b8f5162cbfeb61574e4eef Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sat, 17 Sep 2016 01:47:05 -0400 Subject: [PATCH 4/9] OCA Transbot updated translations from Transifex --- .../i18n/pt_PT.po | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 account_bank_statement_import_camt/i18n/pt_PT.po diff --git a/account_bank_statement_import_camt/i18n/pt_PT.po b/account_bank_statement_import_camt/i18n/pt_PT.po new file mode 100644 index 0000000..7b0f8e8 --- /dev/null +++ b/account_bank_statement_import_camt/i18n/pt_PT.po @@ -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" From 261f3a0213b972abbe1da6c83de1851ad8122163 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 10 Nov 2016 17:18:30 +0100 Subject: [PATCH 5/9] migrate account_bank_statement_import_camt --- account_bank_statement_import_camt/README.rst | 1 + .../__init__.py | 6 +- .../__manifest__.py | 26 ++--- .../account_bank_statement_import.py | 44 -------- account_bank_statement_import_camt/camt.py | 100 +++++++++--------- .../demo/demo_data.xml | 39 +++---- .../models/__init__.py | 4 + .../models/account_bank_statement_import.py | 42 ++++++++ .../{test-camt053.xml => test-camt053} | 0 .../tests/__init__.py | 22 +--- .../tests/test_import_bank_statement.py | 84 ++++++++------- .../views/account_bank_statement_import.xml | 15 +++ 12 files changed, 182 insertions(+), 201 deletions(-) delete mode 100644 account_bank_statement_import_camt/account_bank_statement_import.py create mode 100644 account_bank_statement_import_camt/models/__init__.py create mode 100644 account_bank_statement_import_camt/models/account_bank_statement_import.py rename account_bank_statement_import_camt/test_files/{test-camt053.xml => test-camt053} (100%) create mode 100644 account_bank_statement_import_camt/views/account_bank_statement_import.xml diff --git a/account_bank_statement_import_camt/README.rst b/account_bank_statement_import_camt/README.rst index f027351..a564f7a 100644 --- a/account_bank_statement_import_camt/README.rst +++ b/account_bank_statement_import_camt/README.rst @@ -28,6 +28,7 @@ Credits Contributors ------------ +* Holger Brunn * Stefan Rijnhart * Ronald Portier diff --git a/account_bank_statement_import_camt/__init__.py b/account_bank_statement_import_camt/__init__.py index 7dafcd1..6350c71 100644 --- a/account_bank_statement_import_camt/__init__.py +++ b/account_bank_statement_import_camt/__init__.py @@ -1 +1,5 @@ -from . import account_bank_statement_import +# -*- coding: utf-8 -*- +# © 2013-2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models +from . import camt diff --git a/account_bank_statement_import_camt/__manifest__.py b/account_bank_statement_import_camt/__manifest__.py index 86ce0c5..92e10bd 100644 --- a/account_bank_statement_import_camt/__manifest__.py +++ b/account_bank_statement_import_camt/__manifest__.py @@ -1,25 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2013-2015 Therp BV -# -# 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 . -# -############################################################################## +# © 2013-2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'CAMT Format Bank Statements Import', - 'version': '8.0.0.4.0', + 'version': '9.0.1.0.0', 'license': 'AGPL-3', 'author': 'Odoo Community Association (OCA), Therp BV', 'website': 'https://github.com/OCA/bank-statement-import', @@ -30,5 +14,7 @@ 'demo': [ 'demo/demo_data.xml', ], - 'installable': False, + 'data': [ + 'views/account_bank_statement_import.xml', + ], } diff --git a/account_bank_statement_import_camt/account_bank_statement_import.py b/account_bank_statement_import_camt/account_bank_statement_import.py deleted file mode 100644 index 8814670..0000000 --- a/account_bank_statement_import_camt/account_bank_statement_import.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -"""Add process_camt method to account.bank.statement.import.""" -############################################################################## -# -# Copyright (C) 2013-2015 Therp BV -# -# 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 . -# -############################################################################## -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) diff --git a/account_bank_statement_import_camt/camt.py b/account_bank_statement_import_camt/camt.py index aed01db..d5fa82d 100644 --- a/account_bank_statement_import_camt/camt.py +++ b/account_bank_statement_import_camt/camt.py @@ -1,28 +1,9 @@ # -*- coding: utf-8 -*- """Class to parse camt files.""" -############################################################################## -# -# Copyright (C) 2013-2015 Therp BV -# -# 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 . -# -############################################################################## +# © 2013-2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import re -from datetime import datetime from lxml import etree -from openerp.addons.account_bank_statement_import.parserlib import ( - BankStatement) class CamtParser(object): @@ -58,7 +39,7 @@ class CamtParser(object): attr_value = found_node[0].text else: attr_value = join_str.join([x.text for x in found_node]) - setattr(obj, attr_name, attr_value) + obj[attr_name] = attr_value break def parse_transaction_details(self, ns, node, transaction): @@ -67,16 +48,21 @@ class CamtParser(object): self.add_value_from_node( ns, node, [ './ns:RmtInf/ns:Ustrd', - './ns:AddtlTxInf', './ns:AddtlNtryInf', - ], transaction, 'message', join_str='\n') + './ns:Refs/ns:InstrId', + ], transaction, 'note', join_str='\n') + # name + self.add_value_from_node( + ns, node, [ + './ns:AddtlTxInf', + ], transaction, 'name', join_str='\n') # eref self.add_value_from_node( ns, node, [ './ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref', './ns:Refs/ns:EndToEndId', ], - transaction, 'eref' + transaction, 'ref' ) # remote party values party_type = 'Dbtr' @@ -88,15 +74,15 @@ class CamtParser(object): './ns:RltdPties/ns:%s' % party_type, namespaces={'ns': ns}) if party_node: self.add_value_from_node( - ns, party_node[0], './ns:Nm', transaction, 'remote_owner') + ns, party_node[0], './ns:Nm', transaction, 'partner_name') self.add_value_from_node( ns, party_node[0], './ns:PstlAdr/ns:Ctry', transaction, - 'remote_owner_country' + 'partner_country' ) address_node = party_node[0].xpath( './ns:PstlAdr/ns:AdrLine', namespaces={'ns': ns}) if address_node: - transaction.remote_owner_address = [address_node[0].text] + transaction['partner_address'] = [address_node[0].text] # Get remote_account from iban or from domestic account: account_node = node.xpath( './ns:RltdPties/ns:%sAcct/ns:Id' % party_type, @@ -106,45 +92,52 @@ class CamtParser(object): iban_node = account_node[0].xpath( './ns:IBAN', namespaces={'ns': ns}) if iban_node: - transaction.remote_account = iban_node[0].text + transaction['account_number'] = iban_node[0].text bic_node = node.xpath( './ns:RltdAgts/ns:%sAgt/ns:FinInstnId/ns:BIC' % party_type, namespaces={'ns': ns} ) if bic_node: - transaction.remote_bank_bic = bic_node[0].text + transaction['account_bic'] = bic_node[0].text else: self.add_value_from_node( ns, account_node[0], './ns:Othr/ns:Id', transaction, - 'remote_account' + 'account_number' ) - def parse_transaction(self, ns, node, transaction): + def parse_transaction(self, ns, node): """Parse transaction (entry) node.""" + transaction = {} self.add_value_from_node( ns, node, './ns:BkTxCd/ns:Prtry/ns:Cd', transaction, 'transfer_type' ) + self.add_value_from_node( + ns, node, './ns:BookgDt/ns:Dt', transaction, 'date') self.add_value_from_node( ns, node, './ns:BookgDt/ns:Dt', transaction, 'execution_date') self.add_value_from_node( ns, node, './ns:ValDt/ns:Dt', transaction, 'value_date') - transaction.transferred_amount = self.parse_amount(ns, node) + + transaction['amount'] = self.parse_amount(ns, node) + details_node = node.xpath( './ns:NtryDtls/ns:TxDtls', namespaces={'ns': ns}) if details_node: self.parse_transaction_details(ns, details_node[0], transaction) - if not transaction.message: + if not transaction.get('name'): self.add_value_from_node( - ns, node, './ns:AddtlNtryInf', transaction, 'message') - if not transaction.eref: + ns, node, './ns:AddtlNtryInf', transaction, 'name') + if not transaction.get('name'): + transaction['name'] = '/' + if not transaction.get('ref'): self.add_value_from_node( ns, node, [ './ns:NtryDtls/ns:Btch/ns:PmtInfId', ], - transaction, 'eref' + transaction, 'ref' ) - transaction.data = etree.tostring(node) + transaction['data'] = etree.tostring(node) return transaction def get_balance_amounts(self, ns, node): @@ -182,27 +175,28 @@ class CamtParser(object): def parse_statement(self, ns, node): """Parse a single Stmt node.""" - statement = BankStatement() + result = {} self.add_value_from_node( ns, node, [ './ns:Acct/ns:Id/ns:IBAN', './ns:Acct/ns:Id/ns:Othr/ns:Id', - ], statement, 'local_account' + ], result, 'account_number' ) self.add_value_from_node( - ns, node, './ns:Id', statement, 'statement_id') + ns, node, './ns:Id', result, 'name') + self.add_value_from_node( + ns, node, './ns:Dt', result, 'date') self.add_value_from_node( - ns, node, './ns:Acct/ns:Ccy', statement, 'local_currency') - (statement.start_balance, statement.end_balance) = ( + ns, node, './ns:Acct/ns:Ccy', result, 'currency') + result['balance_start'], result['balance_end_real'] = ( self.get_balance_amounts(ns, node)) transaction_nodes = node.xpath('./ns:Ntry', namespaces={'ns': ns}) + result['transactions'] = [] for entry_node in transaction_nodes: - transaction = statement.create_transaction() - self.parse_transaction(ns, entry_node, transaction) - if statement['transactions']: - statement.date = datetime.strptime( - statement['transactions'][0].execution_date, "%Y-%m-%d") - return statement + transaction = self.parse_transaction(ns, entry_node) + if transaction: + result['transactions'].append(transaction) + return result def check_version(self, ns, root): """Validate validity of camt file.""" @@ -242,8 +236,14 @@ class CamtParser(object): ns = root.tag[1:root.tag.index("}")] self.check_version(ns, root) statements = [] + currency = None + account_number = None for node in root[0][1:]: statement = self.parse_statement(ns, node) if len(statement['transactions']): + if 'currency' in statement: + currency = statement.pop('currency') + if 'account_number' in statement: + account_number = statement.pop('account_number') statements.append(statement) - return statements + return currency, account_number, statements diff --git a/account_bank_statement_import_camt/demo/demo_data.xml b/account_bank_statement_import_camt/demo/demo_data.xml index 7fc44d7..e6313a1 100644 --- a/account_bank_statement_import_camt/demo/demo_data.xml +++ b/account_bank_statement_import_camt/demo/demo_data.xml @@ -1,26 +1,15 @@ - - - - - Bank Journal - (test camt) - TBNKCAMT - bank - - - - - - - - Your Company - NL77ABNA0574908765 - - - - bank - - - - - + + + NL77ABNA0574908765 + + + + + + Bank Journal - (test camt) + TBNKCAMT + bank + + + diff --git a/account_bank_statement_import_camt/models/__init__.py b/account_bank_statement_import_camt/models/__init__.py new file mode 100644 index 0000000..44b3362 --- /dev/null +++ b/account_bank_statement_import_camt/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2013-2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import account_bank_statement_import 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 new file mode 100644 index 0000000..9d711d8 --- /dev/null +++ b/account_bank_statement_import_camt/models/account_bank_statement_import.py @@ -0,0 +1,42 @@ +# -*- 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 +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) diff --git a/account_bank_statement_import_camt/test_files/test-camt053.xml b/account_bank_statement_import_camt/test_files/test-camt053 similarity index 100% rename from account_bank_statement_import_camt/test_files/test-camt053.xml rename to account_bank_statement_import_camt/test_files/test-camt053 diff --git a/account_bank_statement_import_camt/tests/__init__.py b/account_bank_statement_import_camt/tests/__init__.py index cd97bca..06d3af2 100644 --- a/account_bank_statement_import_camt/tests/__init__.py +++ b/account_bank_statement_import_camt/tests/__init__.py @@ -1,23 +1,5 @@ # -*- encoding: utf-8 -*- """Test import of bank statement for camt.053.""" -############################################################################## -# -# Copyright (C) 2015 Therp BV . -# -# 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 . -# -############################################################################## +# © 2013-2016 Therp BV +# 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/tests/test_import_bank_statement.py b/account_bank_statement_import_camt/tests/test_import_bank_statement.py index d14aca9..496ae94 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,52 +1,54 @@ # -*- coding: utf-8 -*- """Run test to import camt.053 import.""" -############################################################################## -# -# Copyright (C) 2015 Therp BV . -# -# 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 . -# -############################################################################## -from openerp.addons.account_bank_statement_import.tests import ( - TestStatementFile) +# © 2013-2016 Therp BV +# 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.""" + transactions = [ + { + 'account_number': 'NL46ABNA0499998748', + 'amount': -754.25, + 'date': '2014-01-05', + 'ref': '435005714488-ABNO33052620', + }, + ] def test_statement_import(self): """Test correct creation of single statement.""" - transactions = [ - { - 'remote_account': 'NL46ABNA0499998748', - 'transferred_amount': -754.25, - 'value_date': '2014-01-05', - 'ref': '435005714488-ABNO33052620', - }, - ] - 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 - ) + 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.""" - self._test_statement_import( - 'account_bank_statement_import_camt', 'test-camt053.zip', - '1234Test/2', # Only name of first statement - local_account='NL77ABNA0574908765', - ) + 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) diff --git a/account_bank_statement_import_camt/views/account_bank_statement_import.xml b/account_bank_statement_import_camt/views/account_bank_statement_import.xml new file mode 100644 index 0000000..1b9b265 --- /dev/null +++ b/account_bank_statement_import_camt/views/account_bank_statement_import.xml @@ -0,0 +1,15 @@ + + + + + account.bank.statement.import + + +
    +
  • CAMT
  • +
  • zipped CAMT
  • +
+
+
+
+
From bc94bd837ca78271a7ad4b6ed2982e3b3751da94 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Fri, 9 Dec 2016 17:29:09 +0100 Subject: [PATCH 6/9] Create demo data during the execution of tests This ensures that the demo chart of accounts is already installed when the bank journal account is created for the bank journal that is needed to test the import. Otherwise, the demo chart from l10n_generic_coa will fail to install because there is already a journal account in the system. --- .../__manifest__.py | 3 --- .../demo/demo_data.xml | 15 --------------- .../tests/test_import_bank_statement.py | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 account_bank_statement_import_camt/demo/demo_data.xml diff --git a/account_bank_statement_import_camt/__manifest__.py b/account_bank_statement_import_camt/__manifest__.py index 92e10bd..2b1a3f5 100644 --- a/account_bank_statement_import_camt/__manifest__.py +++ b/account_bank_statement_import_camt/__manifest__.py @@ -11,9 +11,6 @@ 'depends': [ 'account_bank_statement_import', ], - 'demo': [ - 'demo/demo_data.xml', - ], 'data': [ 'views/account_bank_statement_import.xml', ], diff --git a/account_bank_statement_import_camt/demo/demo_data.xml b/account_bank_statement_import_camt/demo/demo_data.xml deleted file mode 100644 index e6313a1..0000000 --- a/account_bank_statement_import_camt/demo/demo_data.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - NL77ABNA0574908765 - - - - - - Bank Journal - (test camt) - TBNKCAMT - bank - - - 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 496ae94..b043e71 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 @@ -18,6 +18,21 @@ class TestImport(TransactionCase): }, ] + 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 correct creation of single statement.""" action = {} From 933812e4b020967fabcca6cb4924e6486dc8b994 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Fri, 9 Dec 2016 19:13:45 -0500 Subject: [PATCH 7/9] OCA Transbot updated translations from Transifex --- .../i18n/fr_CH.po | 34 +++++++++++++++++++ account_bank_statement_import_camt/i18n/gl.po | 34 +++++++++++++++++++ .../i18n/nb_NO.po | 34 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 account_bank_statement_import_camt/i18n/fr_CH.po create mode 100644 account_bank_statement_import_camt/i18n/gl.po create mode 100644 account_bank_statement_import_camt/i18n/nb_NO.po diff --git a/account_bank_statement_import_camt/i18n/fr_CH.po b/account_bank_statement_import_camt/i18n/fr_CH.po new file mode 100644 index 0000000..3b8e813 --- /dev/null +++ b/account_bank_statement_import_camt/i18n/fr_CH.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_bank_statement_import_camt +# +# Translators: +# OCA Transbot , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-09 17:00+0000\n" +"PO-Revision-Date: 2016-12-09 17:00+0000\n" +"Last-Translator: OCA Transbot , 2016\n" +"Language-Team: French (Switzerland) (https://www.transifex.com/oca/teams/23907/fr_CH/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fr_CH\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "CAMT" +msgstr "" + +#. 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 "Importer Relevé" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "zipped CAMT" +msgstr "" diff --git a/account_bank_statement_import_camt/i18n/gl.po b/account_bank_statement_import_camt/i18n/gl.po new file mode 100644 index 0000000..7ac52f6 --- /dev/null +++ b/account_bank_statement_import_camt/i18n/gl.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_bank_statement_import_camt +# +# Translators: +# Alejandro Santana , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-09 17:00+0000\n" +"PO-Revision-Date: 2016-12-09 17:00+0000\n" +"Last-Translator: Alejandro Santana , 2016\n" +"Language-Team: Galician (https://www.transifex.com/oca/teams/23907/gl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: gl\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "CAMT" +msgstr "" + +#. 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 extracto bancario" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "zipped CAMT" +msgstr "" diff --git a/account_bank_statement_import_camt/i18n/nb_NO.po b/account_bank_statement_import_camt/i18n/nb_NO.po new file mode 100644 index 0000000..8b0659a --- /dev/null +++ b/account_bank_statement_import_camt/i18n/nb_NO.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_bank_statement_import_camt +# +# Translators: +# Imre Kristoffer Eilertsen , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-09 17:00+0000\n" +"PO-Revision-Date: 2016-12-09 17:00+0000\n" +"Last-Translator: Imre Kristoffer Eilertsen , 2016\n" +"Language-Team: Norwegian Bokmål (Norway) (https://www.transifex.com/oca/teams/23907/nb_NO/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: nb_NO\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "CAMT" +msgstr "" + +#. 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 "Importer bankutsagn" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "zipped CAMT" +msgstr "" From 704a01d6f34e42e7f53f5f2cc0ad9e422ff1c307 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Fri, 13 Jan 2017 20:10:08 -0500 Subject: [PATCH 8/9] OCA Transbot updated translations from Transifex --- account_bank_statement_import_camt/i18n/fi.po | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 account_bank_statement_import_camt/i18n/fi.po diff --git a/account_bank_statement_import_camt/i18n/fi.po b/account_bank_statement_import_camt/i18n/fi.po new file mode 100644 index 0000000..09b901e --- /dev/null +++ b/account_bank_statement_import_camt/i18n/fi.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_bank_statement_import_camt +# +# Translators: +# Jarmo Kortetjärvi , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-10 05:00+0000\n" +"PO-Revision-Date: 2016-12-10 05:00+0000\n" +"Last-Translator: Jarmo Kortetjärvi , 2017\n" +"Language-Team: Finnish (https://www.transifex.com/oca/teams/23907/fi/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fi\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "CAMT" +msgstr "" + +#. 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 "Tuo pankkiaineisto" + +#. module: account_bank_statement_import_camt +#: model:ir.ui.view,arch_db:account_bank_statement_import_camt.account_bank_statement_import_view +msgid "zipped CAMT" +msgstr "" From 2ddb8b114ef223033cdaef0cc0b0569f41e38215 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 13 Dec 2016 21:08:12 +0100 Subject: [PATCH 9/9] [MIG] account_bank_statement_import_camt 10.0 --- .../__manifest__.py | 2 +- .../models/account_bank_statement_import.py | 2 +- .../tests/test_import_bank_statement.py | 4 +-- .../views/account_bank_statement_import.xml | 26 +++++++++---------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/account_bank_statement_import_camt/__manifest__.py b/account_bank_statement_import_camt/__manifest__.py index 2b1a3f5..d2415dc 100644 --- a/account_bank_statement_import_camt/__manifest__.py +++ b/account_bank_statement_import_camt/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'CAMT Format Bank Statements Import', - 'version': '9.0.1.0.0', + 'version': '10.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/account_bank_statement_import.py b/account_bank_statement_import_camt/models/account_bank_statement_import.py index 9d711d8..0d6f928 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 @@ -5,7 +5,7 @@ import logging import StringIO import zipfile -from openerp import api, models +from odoo import api, models from ..camt import CamtParser as Parser _logger = logging.getLogger(__name__) 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 b043e71..b3c57aa 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 @@ -3,8 +3,8 @@ # © 2013-2016 Therp BV # 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 +from odoo.tests.common import TransactionCase +from odoo.tools.misc import file_open class TestImport(TransactionCase): diff --git a/account_bank_statement_import_camt/views/account_bank_statement_import.xml b/account_bank_statement_import_camt/views/account_bank_statement_import.xml index 1b9b265..92d3c08 100644 --- a/account_bank_statement_import_camt/views/account_bank_statement_import.xml +++ b/account_bank_statement_import_camt/views/account_bank_statement_import.xml @@ -1,15 +1,13 @@ - - - - account.bank.statement.import - - -
    -
  • CAMT
  • -
  • zipped CAMT
  • -
-
-
-
-
+ + + account.bank.statement.import + + +
    +
  • CAMT
  • +
  • zipped CAMT
  • +
+
+
+