Skip to content

Commit

Permalink
Merge branch 'release/4.20.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Mar 7, 2020
2 parents 13f68ad + 9d157e5 commit af15d69
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 17 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Config file for automatic testing at travis-ci.org

dist: xenial
sudo: false
language: python

Expand All @@ -10,18 +11,24 @@ env:

matrix:
include:
- python: '2.7'
- python: '3.6'
env: TOXENV=docs
- python: '2.7'
- python: '3.6'
env: TOXENV=flake8
- python: '2.7'
env: TOXENV=py27
- python: '3.4'
env: TOXENV=py34
- python: '3.5'
env: TOXENV=py35
- python: '3.6'
env: TOXENV=py36
- python: '3.7'
env: TOXENV=py37
- python: '3.8'
env: TOXENV=py38
- python: '3.9-dev'
env: TOXENV=py39
- python: 'pypy'
env: TOXENV=pypy

cache:
directories:
Expand Down
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
2 changes: 1 addition & 1 deletion mt940/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
statistics and manipulation.
'''.strip().split())
__email__ = 'wolph@wol.ph'
__version__ = '4.19.0'
__version__ = '4.20.0'
__license__ = 'BSD'
__copyright__ = 'Copyright 2015 Rick van Hattem (wolph)'
__url__ = 'https://github.com/WoLpH/mt940'
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
Loading

0 comments on commit af15d69

Please sign in to comment.