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
=== modified file 'account_banking_nl_abnamro/abnamro.py'
--- account_banking_nl_abnamro/abnamro.py 2012-10-27 19:53:50 +0000
+++ account_banking_nl_abnamro/abnamro.py 2013-02-06 22:51:18 +0000
@@ -155,28 +155,46 @@
155 The string consists of slash separated KEY/VALUE pairs,155 The string consists of slash separated KEY/VALUE pairs,
156 but the slash is allowed to and known to occur in VALUE as well!156 but the slash is allowed to and known to occur in VALUE as well!
157 """157 """
158 items = field[1:].split('/') # skip leading slash158 items = field[1:].split('/') # skip leading slash
159 assert len(items) > 1, (
160 _('unable to parse SEPA string: %s - %s') %
161 (field, _('too few items')))
162 known_keys = [
163 'TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF', 'SWOC', 'REMI',
164 'ADDR', 'BIC', 'CPRP', 'CREF', 'CSID', 'ISDT', 'MARF', 'NRTX',
165 'NRTXR', 'PREF', 'PURP', 'REFOB', 'RREF', 'RTYP', 'SVCL',
166 'SWOD'
167 ]
168 # Xtended keys have an extra part, separated from the first part
169 # with a double slash. For example: 'ORIG//CSID'.
170 # The double slash will make that the first part in items is
171 # followed by an empty string item, and then the other part of the
172 # key.
173 extended_keys = [
174 'BENM', 'ORDP', 'ORIG', 'ULTD', 'ULTB'
175 ]
176 known_keys.extend(extended_keys)
177 assert items[0] in known_keys, (
178 _('unable to parse SEPA string: %s - %s') %
179 (field, _('First key unknown %s') % items[0]))
159 sepa_dict = {}180 sepa_dict = {}
160 prev_key = False181 item_index = 0
161 known_keys = ['TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF',182 items_len = len(items)
162 'SWOC', 'REMI', ]183 while item_index < items_len:
163 while items:184 sepa_key = items[item_index]
164 if len(items) == 1:185 sepa_values = []
165 raise osv.except_osv(186 if sepa_key in extended_keys:
166 _('Error !'),187 item_index += 2
167 _("unable to parse SEPA string: %s") % field)188 assert item_index < items_len, (
168 key = items.pop(0)189 _('SEPA key %s missing extention') % sepa_key)
169 if key not in known_keys:190 # For the moment no test on validity of extension
170 # either an unknown key or a value containing a slash191 sepa_key = '//'.join([sepa_key, items[item_index]])
171 if prev_key:192 item_index += 1
172 sepa_dict[prev_key] = sepa_dict[prev_key] + '/' + key193 while (item_index < items_len
173 else:194 and items[item_index] not in known_keys):
174 raise osv.except_osv(195 sepa_values.append(items[item_index].strip())
175 _('Error !'),196 item_index += 1
176 _("unable to parse SEPA string: %s") % field)197 sepa_dict[sepa_key] = '/'.join(sepa_values)
177 else:
178 sepa_dict[key] = items.pop(0).strip()
179 prev_key = key
180 return sepa_dict198 return sepa_dict
181199
182 def parse_type(field):200 def parse_type(field):

Subscribers

People subscribed via source and target branches