From d12419ba872d16d74bf0b3c586515498fa4d6fae Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 31 Jan 2018 12:29:17 +0100 Subject: [PATCH] CAMT import for ING bank Netherlands gives error on saving account lines (#108) * CAMT import for ING bank netherlands gives error on 'transfer to saving account' entries where 'Ntry/NtryDtls/TxDtls/RmtInf/Ustrd' element is missing. Selecting 'Ntry/NtryDtls/TxDtls/RltdPties/CdtrAcct/Tp/Prtry' in this case. Also: The name of the savings account should be last in the list of things to look in for the transaction name, DbtrAcct entry added to catch a meaningful name for to AND from savings account entries. Default added for when nothing is found --- .../__openerp__.py | 1 + account_bank_statement_import_camt/camt.py | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/account_bank_statement_import_camt/__openerp__.py b/account_bank_statement_import_camt/__openerp__.py index f4aff84..dd2195a 100644 --- a/account_bank_statement_import_camt/__openerp__.py +++ b/account_bank_statement_import_camt/__openerp__.py @@ -20,6 +20,7 @@ { 'name': 'CAMT Format Bank Statements Import', 'version': '8.0.0.4.0', + 'summary': 'Module to import SEPA CAMT.053 Format bank statement files', '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 707fdfc..5a6585a 100644 --- a/account_bank_statement_import_camt/camt.py +++ b/account_bank_statement_import_camt/camt.py @@ -21,11 +21,14 @@ ############################################################################## import re +from copy import copy from datetime import datetime from lxml import etree + +from openerp import _ + from openerp.addons.account_bank_statement_import.parserlib import ( BankStatement) -from copy import copy class CamtParser(object): @@ -46,7 +49,8 @@ class CamtParser(object): return amount def add_value_from_node( - self, ns, node, xpath_str, obj, attr_name, join_str=None): + self, ns, node, xpath_str, obj, attr_name, join_str=None, + default=None): """Add value to object from first or all nodes found with xpath. If xpath_str is a list (or iterable), it will be seen as a series @@ -63,16 +67,28 @@ class CamtParser(object): attr_value = join_str.join([x.text for x in found_node]) setattr(obj, attr_name, attr_value) break + else: + if default: + setattr(obj, attr_name, default) def parse_transaction_details(self, ns, node, transaction): """Parse TxDtls node.""" # message self.add_value_from_node( - ns, node, [ + ns, + node, + [ './ns:RmtInf/ns:Ustrd', './ns:AddtlTxInf', './ns:AddtlNtryInf', - ], transaction, 'message', join_str='\n') + './ns:RltdPties/ns:CdtrAcct/ns:Tp/ns:Prtry', + './ns:RltdPties/ns:DbtrAcct/ns:Tp/ns:Prtry', + ], + transaction, + 'message', + join_str='\n', + default=_('No description') + ) # eref self.add_value_from_node( ns, node, [