← Back to team overview

banking-addons-team team mailing list archive

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

 

Ronald Portier (Therp) has proposed merging lp:~therp-nl/banking-addons/6.1_lp1117319_abnamro_sepa_line into lp:banking-addons.

Requested reviews:
  Stefan Rijnhart (Therp) (stefan-therp)
Related bugs:
  Bug #1117319 in Banking Addons: "Not all sepa lines are supported on bank import"
  https://bugs.launchpad.net/banking-addons/+bug/1117319

For more details, see:
https://code.launchpad.net/~therp-nl/banking-addons/6.1_lp1117319_abnamro_sepa_line/+merge/146982

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

Taking into account the remarks by Stefan I streamlined the code , hopefully solving the errors.
-- 
https://code.launchpad.net/~therp-nl/banking-addons/6.1_lp1117319_abnamro_sepa_line/+merge/146982
Your team Banking Addons Team is subscribed to branch lp:banking-addons.
=== 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:58:22 +0000
@@ -155,28 +155,46 @@
             The string consists of slash separated KEY/VALUE pairs,
             but the slash is allowed to and known to occur in VALUE as well!
             """
-            items = field[1:].split('/') # skip leading slash
+            items = field[1:].split('/')  # skip leading slash
+            assert len(items) > 1, (
+                _('unable to parse SEPA string: %s - %s') %
+                (field, _('too few items')))
+            known_keys = [
+                'TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF', 'SWOC', 'REMI',
+                'ADDR', 'BIC', 'CPRP', 'CREF', 'CSID', 'ISDT', 'MARF', 'NRTX',
+                'NRTXR', 'PREF', 'PURP', 'REFOB', 'RREF', 'RTYP', 'SVCL',
+                'SWOD'
+            ]
+            # Xtended keys have an extra part, separated from the first part
+            # with a double slash. For example: 'ORIG//CSID'.
+            # The double slash will make that the first part in items is
+            # followed by an empty string item, and then the other part of the
+            # key.
+            extended_keys = [
+                'BENM', 'ORDP', 'ORIG', 'ULTD', 'ULTB'
+            ]
+            known_keys.extend(extended_keys)
+            assert items[0] in known_keys, (
+                _('unable to parse SEPA string: %s - %s') %
+                (field, _('First key unknown %s') % items[0]))
             sepa_dict = {}
-            prev_key = False
-            known_keys = ['TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF',
-                          'SWOC', 'REMI', ]
-            while items:
-                if len(items) == 1:
-                    raise osv.except_osv(
-                        _('Error !'),
-                        _("unable to parse SEPA string: %s") % field)
-                key = items.pop(0)
-                if key not in known_keys:
-                    # either an unknown key or a value containing a slash
-                    if prev_key:
-                        sepa_dict[prev_key] = sepa_dict[prev_key] + '/' + key
-                    else:
-                        raise osv.except_osv(
-                            _('Error !'),
-                            _("unable to parse SEPA string: %s") % field)
-                else:
-                    sepa_dict[key] = items.pop(0).strip()
-                    prev_key = key
+            item_index = 0
+            items_len = len(items)
+            while item_index < items_len:
+                sepa_key = items[item_index]
+                sepa_values = []
+                if  sepa_key in extended_keys:
+                    item_index += 2
+                    assert item_index < items_len, (
+                        _('SEPA key %s missing extention') % sepa_key)
+                    # For the moment no test on validity of extension
+                    sepa_key = '//'.join([sepa_key, items[item_index]])
+                item_index += 1
+                while (item_index < items_len
+                  and  items[item_index] not in known_keys):
+                    sepa_values.append(items[item_index].strip())
+                    item_index += 1
+                sepa_dict[sepa_key] = '/'.join(sepa_values)
             return sepa_dict
 
         def parse_type(field):


Follow ups