changeset 13:70fa31a08828

Add statement description issue4
author Cédric Krier <ced@b2ck.com>
date Sat, 28 Mar 2015 16:32:12 +0100
parents 992bfc9c7841
children fdd0cc8c664d
files CHANGELOG mt940/MT940.txt mt940/__init__.py mt940/test.py
diffstat 4 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Thu Mar 05 09:46:26 2015 +0100
+++ b/CHANGELOG	Sat Mar 28 16:32:12 2015 +0100
@@ -1,3 +1,4 @@
+* Add Statement description
 * Renamed properties of Transaction to follow the norm
 * Add support for ING specific description format
 
--- a/mt940/MT940.txt	Thu Mar 05 09:46:26 2015 +0100
+++ b/mt940/MT940.txt	Sat Mar 28 16:32:12 2015 +0100
@@ -14,3 +14,4 @@
 DATA
 :61:171214C15,67TIDXTEST//REFERENCE
 :62F:C120514EUR5638,62
+:86:/SUM/
--- a/mt940/__init__.py	Thu Mar 05 09:46:26 2015 +0100
+++ b/mt940/__init__.py	Sat Mar 28 16:32:12 2015 +0100
@@ -78,6 +78,8 @@
 
         with open(name, 'rU') as f:
             values = defaultdict(str)
+            # Set optional values
+            values['description']
             transactions = []
             for line in self._readline(f):
                 for name, sections in SECTIONS.iteritems():
@@ -94,8 +96,12 @@
                                 transactions.append(
                                     self._get_transaction(line[len(section):]))
                             elif name == 'description':
-                                transactions[-1] = (transactions[-1][:-1]
-                                    + (line[len(section):],))
+                                description = line[len(section):]
+                                if 'end_balance' in values:
+                                    values['description'] += description
+                                else:
+                                    transactions[-1] = (transactions[-1][:-1]
+                                        + (description,))
                             else:
                                 values[name] += line[len(section):]
             if values:
@@ -154,7 +160,7 @@
         del transactions[:]
 
 Statement = namedtuple('Statement', ['statement', 'account', 'information',
-        'start_balance', 'transactions', 'end_balance'])
+        'start_balance', 'transactions', 'end_balance', 'description'])
 Balance = namedtuple('Balance', ['date', 'amount', 'currency'])
 Transaction = namedtuple('Transaction', ['date', 'booking', 'amount', 'id',
         'reference', 'institution_reference', 'additional_data',
--- a/mt940/test.py	Thu Mar 05 09:46:26 2015 +0100
+++ b/mt940/test.py	Sat Mar 28 16:32:12 2015 +0100
@@ -70,6 +70,9 @@
         self.assertEqual(end_balance.amount, Decimal('5638.62'))
         self.assertEqual(end_balance.currency, 'EUR')
 
+    def test_statement_description(self):
+        self.assertEqual(self.mt940.statements[0].description, '/SUM/')
+
     def test_transaction(self):
         "Test transaction"
         transaction = self.mt940.statements[0].transactions[0]