From 689688d8176b9b71e3c06de43b3a9065c451e2c9 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 14 Oct 2016 13:32:23 +0000 Subject: [PATCH] [UPD] parse more fields as of (#71) * [UPD] parse more fields for MT940 as of https://www.ing.nl/media/ING_ming_mt940s_24_juli_tcm162-46356.pdf p 8ff * [FIX] There is no CR or LF in mt940 data to be parsed. The calling logic from the MT940 parser concatenates all lines from a mt940 tag. --- .../mt940.py | 22 +++++++++++++++---- .../mt940.py | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/account_bank_statement_import_mt940_base/mt940.py b/account_bank_statement_import_mt940_base/mt940.py index 9ddd9ce..3c36f42 100644 --- a/account_bank_statement_import_mt940_base/mt940.py +++ b/account_bank_statement_import_mt940_base/mt940.py @@ -83,14 +83,28 @@ def handle_common_subfields(transaction, subfields): for counterpart_field in ['CNTP', 'BENM', 'ORDP']: if counterpart_field in subfields: get_counterpart(transaction, subfields[counterpart_field]) + if not transaction.message: + transaction.message = '' # REMI: Remitter information (text entered by other party on trans.): if 'REMI' in subfields: - transaction.message = ( - '/'.join(x for x in subfields['REMI'] if x)) + transaction.message += ( + subfields['REMI'][2] + # this might look like + # /REMI/USTD/// + # or + # /REMI/STRD/CUR// + if len(subfields['REMI']) >= 3 and subfields['REMI'][0] in [ + 'STRD', 'USTD' + ] + else + '/'.join(x for x in subfields['REMI'] if x) + ) + # EREF: End-to-end reference + if 'EREF' in subfields: + transaction.message += '/'.join(filter(bool, subfields['EREF'])) # Get transaction reference subfield (might vary): if transaction.eref in subfields: - transaction.eref = ''.join( - subfields[transaction.eref]) + transaction.eref = ''.join(subfields[transaction.eref]) class MT940(object): diff --git a/account_bank_statement_import_mt940_nl_ing/mt940.py b/account_bank_statement_import_mt940_nl_ing/mt940.py index 5111ab0..a319e93 100644 --- a/account_bank_statement_import_mt940_nl_ing/mt940.py +++ b/account_bank_statement_import_mt940_nl_ing/mt940.py @@ -29,7 +29,8 @@ class MT940Parser(MT940): tag_61_regex = re.compile( r'^(?P\d{6})(?P\d{0,4})' r'(?P[CD])(?P\d+,\d{2})N(?P.{3})' - r'(?P\w{1,50})' + r'(?P\w{0,16})' + r'(//(?P\w{14})/TRCD/(?P\w{0,34})){0,1}' ) def __init__(self): @@ -47,6 +48,7 @@ class MT940Parser(MT940): self.current_transaction.transferred_amount = ( str2amount(parsed_data['sign'], parsed_data['amount'])) self.current_transaction.eref = parsed_data['reference'] + self.current_transaction.id = parsed_data['ingid'] def handle_tag_86(self, data): """Parse 86 tag containing reference data."""