From 3d627657ced6b562e606986d159e62ade45c2a7f Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Tue, 24 Jan 2017 17:06:29 +0100 Subject: [PATCH] [FIX] Prioritize batch node over details. --- .../models/parser.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/account_bank_statement_import_camt/models/parser.py b/account_bank_statement_import_camt/models/parser.py index 9648f84..3eb6d50 100644 --- a/account_bank_statement_import_camt/models/parser.py +++ b/account_bank_statement_import_camt/models/parser.py @@ -158,18 +158,23 @@ class CamtParser(models.AbstractModel): self.add_value_from_node( node, './ns:ValDt/ns:Dt', transaction, 'value_date') transaction.transferred_amount = self.parse_amount(node) - self.add_value_from_node( - node, './ns:AddtlNtryInf', transaction, 'name') - self.add_value_from_node( - ns, node, [ - './ns:NtryDtls/ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref', - './ns:NtryDtls/ns:Btch/ns:PmtInfId', - ], - transaction, 'eref' - ) + batch_node = self.xpath(node, './ns:NtryDtls/ns:Btch') + if batch_node: + self.add_value_from_node( + batch_node[0], './ns:PmtInfId', transaction, 'eref') + else: + self.add_value_from_node( + node, './ns:AddtlNtryInf', transaction, 'name') + self.add_value_from_node( + node, + ['./ns:NtryDtls/ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref', + './ns:NtryDtls/ns:Btch/ns:PmtInfId'], + transaction, + 'eref') details_nodes = node.xpath( './ns:NtryDtls/ns:TxDtls', namespaces={'ns': ns}) if len(details_nodes) == 0: + transaction.data = etree.tostring(node) yield transaction return transaction_base = transaction