Repository: ministryofjustice/mt940-writer

Issue:
add support for Tag 86
<img width="651" alt="image" src="https://github.com/ministryofjustice/mt940-writer/assets/20453622/fb184e68-7eaf-4b13-89c4-f6075d2f28b8">

<img width="474" alt="image" src="https://github.com/ministryofjustice/mt940-writer/assets/20453622/6e08494e-b5f5-41f5-8c97-50de4b552165">


Discussion:

Patch:
diff --git a/mt940_writer.py b/mt940_writer.py
index b6a3ad9..f3577ac 100644
--- a/mt940_writer.py
+++ b/mt940_writer.py
@@ -58,11 +58,12 @@ class Balance:
 
 
 class Transaction:
-    def __init__(self, date, amount, transaction_type, narrative):
+    def __init__(self, date, amount, transaction_type, narrative, additional_info=None):
         self.date = date
         self.amount = amount
         self.transaction_type = transaction_type
         self.narrative = narrative
+        self.additional_info = additional_info
 
     def __str__(self):
         return '{value_date}{entry_date}{category}{amount}{type_code}{narrative}'.format(
@@ -75,6 +76,18 @@ class Transaction:
         )
 
 
+class TransactionAdditionalInfo:
+    def __init__(self, information):
+        self.information = information
+
+    def __str__(self):
+        return '{information}'.format(
+            information=self.information,
+        )
+
+    def __bool__(self):
+        return bool(self.information)
+
 class Statement:
     def __init__(self, reference_number, account, statement_number, opening_balance, closing_balance, transactions):
         self.reference_number = reference_number
@@ -91,6 +104,8 @@ class Statement:
         yield ':60F:%s' % self.opening_balance
         for transaction in self.transactions:
             yield ':61:%s' % transaction
+            if transaction.additional_info:
+                yield ':86:%s' % transaction.additional_info
         yield ':62F:%s' % self.closing_balance
 
     def __str__(self):


Test patch:
diff --git a/tests/test_mt940_writer.py b/tests/test_mt940_writer.py
index cf4e232..aa7afd7 100644
--- a/tests/test_mt940_writer.py
+++ b/tests/test_mt940_writer.py
@@ -5,19 +5,6 @@ from unittest import TestCase
 import mt940_writer as mt940
 
 
-EXPECTED_OUTPUT = (
-    ':20:59716\n'
-    ':25:80008000 102030\n'
-    ':28C:1/1\n'
-    ':60F:C160922GBP12,99\n'
-    ':61:1609220922C1,00NTRFPayment 1\n'
-    ':61:1609220922C1,00NMSCPayment 2\n'
-    ':61:1609220922C1,00NTRFPayment 3\n'
-    ':61:1609220922D0,99NMSCPayment 4\n'
-    ':62F:C160922GBP15,00'
-)
-
-
 class MT940WriterTestCase(TestCase):
 
     def test_write_statement(self):
@@ -32,6 +19,18 @@ class MT940WriterTestCase(TestCase):
             mt940.Transaction(stmt_date, Decimal('-0.99'), mt940.TransactionType.miscellaneous, 'Payment 4')
         ]
 
+        expected_output = (
+            ':20:59716\n'
+            ':25:80008000 102030\n'
+            ':28C:1/1\n'
+            ':60F:C160922GBP12,99\n'
+            ':61:1609220922C1,00NTRFPayment 1\n'
+            ':61:1609220922C1,00NMSCPayment 2\n'
+            ':61:1609220922C1,00NTRFPayment 3\n'
+            ':61:1609220922D0,99NMSCPayment 4\n'
+            ':62F:C160922GBP15,00'
+        )
+
         statement = mt940.Statement(
             '59716',
             account,
@@ -41,4 +40,42 @@ class MT940WriterTestCase(TestCase):
             transactions
         )
 
-        self.assertEqual(str(statement), EXPECTED_OUTPUT)
+        self.assertEqual(str(statement), expected_output)
+    def test_write_statement_with_additional_transaction_info(self):
+            stmt_date = date(2016, 9, 22)
+            account = mt940.Account('80008000', '102030')
+            opening_balance = mt940.Balance(Decimal('12.99'), stmt_date, 'GBP')
+            closing_balance = mt940.Balance(Decimal('15'), stmt_date, 'GBP')
+            transactions = [
+                mt940.Transaction(stmt_date, Decimal('1'), mt940.TransactionType.transfer, 'Payment 1',
+                                  mt940.TransactionAdditionalInfo('ADDITIONAL/DATA/1')),
+                mt940.Transaction(stmt_date, Decimal('1'), mt940.TransactionType.miscellaneous, 'Payment 2',
+                                  mt940.TransactionAdditionalInfo('ADDITIONAL/DATA/2')),
+                mt940.Transaction(stmt_date, Decimal('1'), mt940.TransactionType.transfer, 'Payment 3',
+                                  mt940.TransactionAdditionalInfo('')),
+                mt940.Transaction(stmt_date, Decimal('-0.99'), mt940.TransactionType.miscellaneous, 'Payment 4')
+            ]
+
+            expected_output = (
+                ':20:59716\n'
+                ':25:80008000 102030\n'
+                ':28C:1/1\n'
+                ':60F:C160922GBP12,99\n'
+                ':61:1609220922C1,00NTRFPayment 1\n'
+                ':86:ADDITIONAL/DATA/1\n'
+                ':61:1609220922C1,00NMSCPayment 2\n'
+                ':86:ADDITIONAL/DATA/2\n'
+                ':61:1609220922C1,00NTRFPayment 3\n'
+                ':61:1609220922D0,99NMSCPayment 4\n'
+                ':62F:C160922GBP15,00'
+            )
+            statement = mt940.Statement(
+                '59716',
+                account,
+                '1/1',
+                opening_balance,
+                closing_balance,
+                transactions
+            )
+
+            self.assertEqual(str(statement), expected_output)