Merge lp:~therp-nl/banking-addons/6.1_lp1117319_abnamro_sepa_line into lp:banking-addons/6.1

Proposed by Ronald Portier (Therp)
Status: Superseded
Proposed branch: lp:~therp-nl/banking-addons/6.1_lp1117319_abnamro_sepa_line
Merge into: lp:banking-addons/6.1
Diff against target: 71 lines (+39/-21)
1 file modified
account_banking_nl_abnamro/abnamro.py (+39/-21)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/6.1_lp1117319_abnamro_sepa_line
Reviewer Review Type Date Requested Status
Stefan Rijnhart (Opener) Needs Fixing
Review via email: mp+146903@code.launchpad.net

This proposal has been superseded by a proposal from 2013-02-06.

Description of the change

Make it possible to import abnamro statement files with extended sepa attributes in line.

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks for fixing this!

l.8,28 Maybe combine in a single dictionary of possible keys?
l.62 Looks like the last key/value pair is not stored in sepa_dict. You could copy this line after the end of the 'while' loop.

review: Needs Fixing
162. By Ronald Portier (Therp)

[FIX] Improved on bug fix in previous revision, to
      not forget the last value in the sepa dictionary.

      Go through all items in sepa line in old school JSP nested loop.

163. By Ronald Portier (Therp)

[FIX] Updated parsing of abnamro sepa string to handle even more unlikely cases.

164. By Ronald Portier (Therp)

[FIX] More meaningfull names for index variable names.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_banking_nl_abnamro/abnamro.py'
2--- account_banking_nl_abnamro/abnamro.py 2012-10-27 19:53:50 +0000
3+++ account_banking_nl_abnamro/abnamro.py 2013-02-06 22:51:18 +0000
4@@ -155,28 +155,46 @@
5 The string consists of slash separated KEY/VALUE pairs,
6 but the slash is allowed to and known to occur in VALUE as well!
7 """
8- items = field[1:].split('/') # skip leading slash
9+ items = field[1:].split('/') # skip leading slash
10+ assert len(items) > 1, (
11+ _('unable to parse SEPA string: %s - %s') %
12+ (field, _('too few items')))
13+ known_keys = [
14+ 'TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF', 'SWOC', 'REMI',
15+ 'ADDR', 'BIC', 'CPRP', 'CREF', 'CSID', 'ISDT', 'MARF', 'NRTX',
16+ 'NRTXR', 'PREF', 'PURP', 'REFOB', 'RREF', 'RTYP', 'SVCL',
17+ 'SWOD'
18+ ]
19+ # Xtended keys have an extra part, separated from the first part
20+ # with a double slash. For example: 'ORIG//CSID'.
21+ # The double slash will make that the first part in items is
22+ # followed by an empty string item, and then the other part of the
23+ # key.
24+ extended_keys = [
25+ 'BENM', 'ORDP', 'ORIG', 'ULTD', 'ULTB'
26+ ]
27+ known_keys.extend(extended_keys)
28+ assert items[0] in known_keys, (
29+ _('unable to parse SEPA string: %s - %s') %
30+ (field, _('First key unknown %s') % items[0]))
31 sepa_dict = {}
32- prev_key = False
33- known_keys = ['TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF',
34- 'SWOC', 'REMI', ]
35- while items:
36- if len(items) == 1:
37- raise osv.except_osv(
38- _('Error !'),
39- _("unable to parse SEPA string: %s") % field)
40- key = items.pop(0)
41- if key not in known_keys:
42- # either an unknown key or a value containing a slash
43- if prev_key:
44- sepa_dict[prev_key] = sepa_dict[prev_key] + '/' + key
45- else:
46- raise osv.except_osv(
47- _('Error !'),
48- _("unable to parse SEPA string: %s") % field)
49- else:
50- sepa_dict[key] = items.pop(0).strip()
51- prev_key = key
52+ item_index = 0
53+ items_len = len(items)
54+ while item_index < items_len:
55+ sepa_key = items[item_index]
56+ sepa_values = []
57+ if sepa_key in extended_keys:
58+ item_index += 2
59+ assert item_index < items_len, (
60+ _('SEPA key %s missing extention') % sepa_key)
61+ # For the moment no test on validity of extension
62+ sepa_key = '//'.join([sepa_key, items[item_index]])
63+ item_index += 1
64+ while (item_index < items_len
65+ and items[item_index] not in known_keys):
66+ sepa_values.append(items[item_index].strip())
67+ item_index += 1
68+ sepa_dict[sepa_key] = '/'.join(sepa_values)
69 return sepa_dict
70
71 def parse_type(field):

Subscribers

People subscribed via source and target branches