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