From 7b288517446499f00464751e52c70efa5868b0dc Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Wed, 5 Jun 2013 14:30:03 +0200 Subject: [PATCH] [IMP] nl_ing: implement support for acceptgiros --- account_banking_nl_ing/ing.py | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/account_banking_nl_ing/ing.py b/account_banking_nl_ing/ing.py index 33dbcdb95..929384c6a 100644 --- a/account_banking_nl_ing/ing.py +++ b/account_banking_nl_ing/ing.py @@ -77,6 +77,7 @@ class transaction_message(object): # Normalize basic account numbers self.remote_account = self.remote_account.replace('.', '').zfill(10) self.local_account = self.local_account.replace('.', '').zfill(10) + class transaction(models.mem_bank_transaction): ''' @@ -114,6 +115,8 @@ class transaction(models.mem_bank_transaction): # global expression for matching storno references ref_expr = re.compile('REF[\*:]([0-9A-Z-z_-]+)') + # match references for Acceptgiro's through Internet banking + kn_expr = re.compile('KN: ([^ ]+)') def __init__(self, line, *args, **kwargs): ''' @@ -149,6 +152,58 @@ class transaction(models.mem_bank_transaction): self.reference = res.group(1) self.storno_retry = True self.remote_owner = False + if self.transfer_type == 'GT': + res = self.kn_expr.search(self.message) + if res: + self.reference = res.group(1) + if self.transfer_type == 'AC': + self.parse_acceptgiro() + if self.message and not self.reference: + self.reference = self.message + + def parse_acceptgiro(self): + """ + Entries of type 'Acceptgiro' can contain the reference + in the 'name' column, as well as full address information + in the 'message' column' + """ + reference = '' + street = False + zipcode = False + street = False + before = False + if self.remote_owner.startswith('KN: '): + self.reference = self.remote_owner[4:] + self.remote_owner = '' + if 'KN: ' in self.message: + index = self.message.index('KN: ') + before = self.message[:index] + self.message = self.message[index:] + expression = ( + "^\s*(KN:\s*(?P[^\s]+))?(\s*)" + "(?PNAVR:\s*[^\s]+)?(\s*)(?P.*?)$") + msg_match = re.match(expression, self.message) + after = msg_match.group('after') + kn = msg_match.group('kn') + navr = msg_match.group('navr') + if kn: + self.reference = kn[4:] + self.message = 'Acceptgiro %s' % (navr or '') + if after: + parts = [after[i:i+33] for i in range(0, len(after), 33)] + if parts and not self.remote_owner: + self.remote_owner = parts.pop(0).strip() + if parts: + self.remote_owner_address = [parts.pop(0).strip()] + if parts: + zip_city = parts.pop(0).strip() + zip_match = re.match( + "^(?P[^ ]{6})\s+(?P.*?)$", zip_city) + if zip_match: + self.remote_owner_postalcode = zip_match.group('zipcode') + self.remote_owner_city = zip_match.group('city') + if before and not self.remote_owner_city: + self.remote_owner_city = before.strip() def is_valid(self): if not self.error_message: