Skip to content

Commit

Permalink
Merge branch 'feature/asnb-tag-61' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Mar 7, 2020
2 parents 3ea681d + 9157791 commit 3d609a4
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 11 deletions.
20 changes: 19 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ Simple json encoding:
print(json.dumps(transactions, indent=4, cls=mt940.JSONEncoder))
Parsing statements from the Dutch bank ASN where tag 61 does not follow the Swift specifications:

.. code-block:: python
def ASNB_mt940_data():
with open('mt940_tests/ASNB/0708271685_09022020_164516.940.txt') as fh:
return fh.read()
def test_ASNB_tags(ASNB_mt940_data):
tag_parser = mt940.tags.StatementASNB()
trs = mt940.models.Transactions(tags={
tag_parser.id: tag_parser
})
trs.parse(ASNB_mt940_data)
trs_data = pprint.pformat(trs.data, sort_dicts=False)
print(trs_data)
Contributing
------------

Expand All @@ -137,7 +155,7 @@ To run the tests:
pip install -r mt940_tests/requirements.txt
py.test
Or to run the tests on all available Python versions:

.. code-block:: shell
Expand Down
17 changes: 13 additions & 4 deletions mt940/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@


class Model(object):
pass

def __repr__(self):
return '<%s>' % self.__class__.__name__


class FixedOffset(datetime.tzinfo):
Expand Down Expand Up @@ -166,10 +168,14 @@ def __init__(self, amount, status, currency=None, **kwargs):
if status == 'D':
self.amount = -self.amount

def __eq__(self, other):
return self.amount == other.amount and self.currency == other.currency

def __str__(self):
return '%s %s' % (self.amount, self.currency)

def __repr__(self):
return '<%s %s>' % (
self.amount,
self.currency, )
return '<%s>' % self


class SumAmount(Amount):
Expand Down Expand Up @@ -212,6 +218,9 @@ def __init__(self, status=None, amount=None, date=None, **kwargs):
self.amount = amount
self.date = date

def __eq__(self, other):
return self.amount == other.amount and self.status == other.status

def __repr__(self):
return '<%s>' % self

Expand Down
37 changes: 37 additions & 0 deletions mt940/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,43 @@ def __call__(self, transactions, value):
return data


class StatementASNB(Statement):
'''StatementASNB
From: https://www.sepaforcorporates.com/swift-for-corporates
Pattern: 6!n[4!n]2a[1!a]15d1!a3!c16x[//16x]
[34x]
But ASN bank puts the IBAN in the customer reference, which is acording to
Wikipedia at most 34 characters.
So this is the new pattern:
Pattern: 6!n[4!n]2a[1!a]15d1!a3!c34x[//16x]
[34x]
'''
pattern = r'''^
(?P<year>\d{2}) # 6!n Value Date (YYMMDD)
(?P<month>\d{2})
(?P<day>\d{2})
(?P<entry_month>\d{2})? # [4!n] Entry Date (MMDD)
(?P<entry_day>\d{2})?
(?P<status>[A-Z]?[DC]) # 2a Debit/Credit Mark
(?P<funds_code>[A-Z])? # [1!a] Funds Code (3rd character of the currency
# code, if needed)
\n? # apparently some banks (sparkassen) incorporate newlines here
(?P<amount>[\d,]{1,15}) # 15d Amount
(?P<id>[A-Z][A-Z0-9 ]{3})? # 1!a3!c Transaction Type Identification Code
(?P<customer_reference>.{0,34}) # 34x Customer Reference
(//(?P<bank_reference>.{0,16}))? # [//16x] Bank Reference
(\n?(?P<extra_details>.{0,34}))? # [34x] Supplementary Details
$'''

def __call__(self, transactions, value):
return super(StatementASNB, self).__call__(transactions, value)


class ClosingBalance(BalanceBase):
id = 62

Expand Down
280 changes: 280 additions & 0 deletions mt940_tests/ASNB/0708271685_09022020_164516.940.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:1/1
:60F:C200101EUR444,29
:61:2001010101D65,00NOVBNL47INGB9999999999
hr gjlm paulissen
:86:NL47INGB9999999999 hr gjlm paulissen

Betaling sieraden



:62F:C200101EUR379,29
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:2/1
:60F:C200102EUR379,29
:62F:C200102EUR379,29
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:3/1
:60F:C200103EUR379,29
:62F:C200103EUR379,29
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:4/1
:60F:C200104EUR379,29
:62F:C200104EUR379,29
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:5/1
:60F:C200105EUR379,29
:61:2001050105C1000,00NIOBNL56ASNB9999999999
paulissen g j l m
:86:NL56ASNB9999999999 paulissen g j l m

INTERNE OVERBOEKING VIA MOBIEL



:61:2001050105D801,55NIDBNL08ABNA9999999999
international card services
:86:NL08ABNA9999999999 international card services

000000000000000000000000000000000 0000000000000000 Betaling aan I
CS 99999999999 ICS Referentie: 2020-01-05 19:47 000000000000000


:62F:C200105EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:6/1
:60F:C200106EUR577,74
:62F:C200106EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:7/1
:60F:C200107EUR577,74
:62F:C200107EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:8/1
:60F:C200108EUR577,74
:62F:C200108EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:9/1
:60F:C200109EUR577,74
:62F:C200109EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:10/1
:60F:C200110EUR577,74
:62F:C200110EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:11/1
:60F:C200111EUR577,74
:62F:C200111EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:12/1
:60F:C200112EUR577,74
:62F:C200112EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:13/1
:60F:C200113EUR577,74
:62F:C200113EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:14/1
:60F:C200114EUR577,74
:62F:C200114EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:15/1
:60F:C200115EUR577,74
:62F:C200115EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:16/1
:60F:C200116EUR577,74
:62F:C200116EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:17/1
:60F:C200117EUR577,74
:62F:C200117EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:18/1
:60F:C200118EUR577,74
:62F:C200118EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:19/1
:60F:C200119EUR577,74
:62F:C200119EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:20/1
:60F:C200120EUR577,74
:62F:C200120EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:21/1
:60F:C200121EUR577,74
:62F:C200121EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:22/1
:60F:C200122EUR577,74
:62F:C200122EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:23/1
:60F:C200123EUR577,74
:62F:C200123EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:24/1
:60F:C200124EUR577,74
:62F:C200124EUR577,74
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:25/1
:60F:C200125EUR577,74
:61:2001250125D1,65NDIV
:86:

Kosten gebruik betaalrekening inclusief 1 betaalpas



:62F:C200125EUR576,09
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:26/1
:60F:C200126EUR576,09
:62F:C200126EUR576,09
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:27/1
:60F:C200127EUR576,09
:62F:C200127EUR576,09
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:28/1
:60F:C200128EUR576,09
:62F:C200128EUR576,09
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:29/1
:60F:C200129EUR576,09
:61:2001290129C828,72NOVBNL25INGB9999999999
transfer solutions bv
:86:NL25INGB9999999999 transfer solutions bv

2020-01-28T14:32:46-000000000000089-NL25INGB9999999999-Transfer S
olutions BV-DIVIDEND 28/01/2020


:61:2001290129D1000,00NIDBNL08ABNA9999999999
international card services
:86:NL08ABNA9999999999 international card services

000000000000000000000000000000000 0000000000000000 Betaling aan I
CS 99999999999 ICS Referentie: 2020-01-29 18:36 000000000000000


:62F:C200129EUR404,81
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:30/1
:60F:C200130EUR404,81
:62F:C200130EUR404,81
-}{5:}
{1:F01ASNBNL21XXXX0000000000}{2:O940ASNBNL21XXXXN}{3:}{4:
:20:0000000000
:25:NL81ASNB9999999999
:28C:31/1
:60F:C200131EUR404,81
:61:2001310131C1000,18NIOBNL56ASNB9999999999
paulissen g j l m
:86:NL56ASNB9999999999 paulissen g j l m

INTERNE OVERBOEKING VIA MOBIEL



:61:2001310131D903,76NIDBNL08ABNA9999999999
international card services
:86:NL08ABNA9999999999 international card services

000000000000000000000000000000000 0000000000000000 Betaling aan I
CS 99999999999 ICS Referentie: 2020-01-31 21:27 000000000000000


:62F:C200131EUR501,23
-}{5:}
Loading

0 comments on commit 3d609a4

Please sign in to comment.