Merge lp:~therp-nl/banking-addons/ba70-ing_acceptgiros into lp:banking-addons

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 173
Proposed branch: lp:~therp-nl/banking-addons/ba70-ing_acceptgiros
Merge into: lp:banking-addons
Diff against target: 79 lines (+55/-0)
1 file modified
account_banking_nl_ing/ing.py (+55/-0)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/ba70-ing_acceptgiros
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Review via email: mp+167523@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_banking_nl_ing/ing.py'
2--- account_banking_nl_ing/ing.py 2013-04-15 13:56:18 +0000
3+++ account_banking_nl_ing/ing.py 2013-06-05 12:32:32 +0000
4@@ -77,6 +77,7 @@
5 # Normalize basic account numbers
6 self.remote_account = self.remote_account.replace('.', '').zfill(10)
7 self.local_account = self.local_account.replace('.', '').zfill(10)
8+
9
10 class transaction(models.mem_bank_transaction):
11 '''
12@@ -114,6 +115,8 @@
13
14 # global expression for matching storno references
15 ref_expr = re.compile('REF[\*:]([0-9A-Z-z_-]+)')
16+ # match references for Acceptgiro's through Internet banking
17+ kn_expr = re.compile('KN: ([^ ]+)')
18
19 def __init__(self, line, *args, **kwargs):
20 '''
21@@ -149,6 +152,58 @@
22 self.reference = res.group(1)
23 self.storno_retry = True
24 self.remote_owner = False
25+ if self.transfer_type == 'GT':
26+ res = self.kn_expr.search(self.message)
27+ if res:
28+ self.reference = res.group(1)
29+ if self.transfer_type == 'AC':
30+ self.parse_acceptgiro()
31+ if self.message and not self.reference:
32+ self.reference = self.message
33+
34+ def parse_acceptgiro(self):
35+ """
36+ Entries of type 'Acceptgiro' can contain the reference
37+ in the 'name' column, as well as full address information
38+ in the 'message' column'
39+ """
40+ reference = ''
41+ street = False
42+ zipcode = False
43+ street = False
44+ before = False
45+ if self.remote_owner.startswith('KN: '):
46+ self.reference = self.remote_owner[4:]
47+ self.remote_owner = ''
48+ if 'KN: ' in self.message:
49+ index = self.message.index('KN: ')
50+ before = self.message[:index]
51+ self.message = self.message[index:]
52+ expression = (
53+ "^\s*(KN:\s*(?P<kn>[^\s]+))?(\s*)"
54+ "(?P<navr>NAVR:\s*[^\s]+)?(\s*)(?P<after>.*?)$")
55+ msg_match = re.match(expression, self.message)
56+ after = msg_match.group('after')
57+ kn = msg_match.group('kn')
58+ navr = msg_match.group('navr')
59+ if kn:
60+ self.reference = kn[4:]
61+ self.message = 'Acceptgiro %s' % (navr or '')
62+ if after:
63+ parts = [after[i:i+33] for i in range(0, len(after), 33)]
64+ if parts and not self.remote_owner:
65+ self.remote_owner = parts.pop(0).strip()
66+ if parts:
67+ self.remote_owner_address = [parts.pop(0).strip()]
68+ if parts:
69+ zip_city = parts.pop(0).strip()
70+ zip_match = re.match(
71+ "^(?P<zipcode>[^ ]{6})\s+(?P<city>.*?)$", zip_city)
72+ if zip_match:
73+ self.remote_owner_postalcode = zip_match.group('zipcode')
74+ self.remote_owner_city = zip_match.group('city')
75+ if before and not self.remote_owner_city:
76+ self.remote_owner_city = before.strip()
77
78 def is_valid(self):
79 if not self.error_message:

Subscribers

People subscribed via source and target branches

to status/vote changes: