changeset 21:8894defcb0e5 0.3

Add support for RegioBank description format bug7
author Cédric Krier <ced@b2ck.com>
date Wed, 27 Jan 2016 10:31:10 +0100
parents 667ccb8f2e31
children 858384e339b0
files CHANGELOG mt940/__init__.py mt940/test.py
diffstat 3 files changed, 63 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Tue Jan 19 10:20:06 2016 +0100
+++ b/CHANGELOG	Wed Jan 27 10:31:10 2016 +0100
@@ -1,3 +1,4 @@
+* Add support for RegioBank description format
 * Set a default description after setting a statement
 
 Version 0.2 - 2015-04-29
--- a/mt940/__init__.py	Tue Jan 19 10:20:06 2016 +0100
+++ b/mt940/__init__.py	Wed Jan 27 10:31:10 2016 +0100
@@ -1,9 +1,9 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-# Copyright (c) 2013, Cédric Krier
+# Copyright (c) 2013-2016, Cédric Krier
 # Copyright (c) 2014-2015, Nicolas Évrard
-# Copyright (c) 2013-2015, B2CK
+# Copyright (c) 2013-2016, B2CK
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
 """
 __version__ = '0.3'
 __all__ = ['MT940', 'rabo_description', 'abn_amro_description',
-    'ing_description']
+    'ing_description', 'regiobank_description']
 
 from collections import namedtuple, defaultdict
 from decimal import Decimal
@@ -280,3 +280,24 @@
                 values[name][sf_name] = sf_value
 
     return values
+
+
+def regiobank_description(description):
+    "Return dictionary with RegioBank informations"
+    lines = description.splitlines()
+    values = {}
+    try:
+        first, second, third = lines[0], lines[1], ''.join(lines[2:])
+    except (ValueError, IndexError):
+        return {}
+    try:
+        values['account_number'], values['name'] = first.split(' ', 1)
+    except ValueError:
+        return {}
+    values['address'] = second  # XXX Not clear how to split it
+    if third.startswith('aan %s' % values['name']):
+        _, values['iban'], values['remittance_info'], values['description'] = \
+                third.split(',')
+    else:
+        values['reference'] = third
+    return values
--- a/mt940/test.py	Tue Jan 19 10:20:06 2016 +0100
+++ b/mt940/test.py	Wed Jan 27 10:31:10 2016 +0100
@@ -36,7 +36,7 @@
 
 here = os.path.dirname(__file__)
 from mt940 import (MT940, rabo_description, abn_amro_description,
-    ing_description)
+    ing_description, regiobank_description)
 
 
 class TestMT940(unittest.TestCase):
@@ -180,5 +180,42 @@
         self.assertEqual(ing_description('foo'), {})
         self.assertEqual(ing_description('/FOO/BAR/NAME/'), {})
 
+
+class TestRegioBankDescription(unittest.TestCase):
+
+    def test_reference(self):
+        description = """0102792984 jyhhenewr f j k
+
+rgt-test-004"""
+
+        self.assertEqual(regiobank_description(description), {
+                'account_number': '0102792984',
+                'name': 'jyhhenewr f j k',
+                'address': '',
+                'reference': 'rgt-test-004',
+                })
+
+    def test_sepa(self):
+        description = """0707464188 dsfg w van
+
+aan dsfg w van,nl04asnb070746418 8,sct2013021540684000000000004,
+t est 1"""
+
+        self.assertEqual(regiobank_description(description), {
+                'account_number': '0707464188',
+                'name': 'dsfg w van',
+                'address': '',
+                'iban': 'nl04asnb070746418 8',
+                'remittance_info': 'sct2013021540684000000000004',
+                'description': 't est 1',
+                })
+
+    def test_non_regiobank(self):
+        self.assertEqual(regiobank_description('foo'), {})
+        description = """foo
+bar
+test"""
+        self.assertEqual(regiobank_description(description), {})
+
 if __name__ == '__main__':
     unittest.main()