Skip to content

Commit

Permalink
Merge pull request #13 from mlaitinen/ofxstatement-0.6.5-compatibility
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
mlaitinen authored Nov 29, 2020
2 parents ef16056 + a127e55 commit 6f1e598
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: python

python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"

install:
- pip install -e .[test]
Expand Down
6 changes: 6 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.6.0
-----

- Since version 0.6.5 ofxstatement requires a statement line to have either id, refnum or check_no. To avoid failing
the conversion, there's now a unique MD5 hashed ID computed from the date, payee, amount and balance.

1.5.0
-----

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import unittest

version = "1.5.0"
version = "1.6.0"

setup(name='ofxstatement-revolut',
version=version,
Expand Down
6 changes: 6 additions & 0 deletions src/ofxstatement/plugins/revolut.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
import re
from datetime import datetime
from hashlib import md5

from ofxstatement.plugin import Plugin
from ofxstatement.parser import CsvStatementParser
Expand Down Expand Up @@ -124,6 +125,11 @@ def parse_record(self, line):
stmt_line.memo += u' '
stmt_line.memo += u'({})'.format(line[c["Notes"]].strip())

# Generate a unique ID
balance = self.parse_amount(line[c["Balance (...)"]])
stmt_line.id = md5(f"{stmt_line.date}-{stmt_line.payee}-{stmt_line.amount}-{balance}".encode())\
.hexdigest()

return stmt_line


Expand Down
2 changes: 1 addition & 1 deletion src/ofxstatement/tests/samples/2018-april.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ OLDFILEUID:NONE
NEWFILEUID:NONE
-->

<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><DTSERVER>20181111141713</DTSERVER><LANGUAGE>ENG</LANGUAGE></SONRS></SIGNONMSGSRSV1><BANKMSGSRSV1><STMTTRNRS><TRNUID>0</TRNUID><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><STMTRS><CURDEF>EUR</CURDEF><BANKACCTFROM><BANKID>Revolut</BANKID><ACCTID>Revolut - EUR</ACCTID><ACCTTYPE>CHECKING</ACCTTYPE></BANKACCTFROM><BANKTRANLIST><DTSTART /><DTEND /><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180408</DTPOSTED><TRNAMT>-11.00</TRNAMT><NAME>Shop A</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-49.76</TRNAMT><NAME>Shop B</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-8.00</TRNAMT><NAME>Shop C</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-17.37</TRNAMT><NAME>Shop D</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-1.95</TRNAMT><NAME>Shop E</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180405</DTPOSTED><TRNAMT>-5.40</TRNAMT><NAME>Shop F</NAME></STMTTRN><STMTTRN><TRNTYPE>DEP</TRNTYPE><DTPOSTED>20180402</DTPOSTED><TRNAMT>200.00</TRNAMT><MEMO>Top-Up by *1234</MEMO></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180402</DTPOSTED><TRNAMT>-15.54</TRNAMT><NAME>Shop G</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180401</DTPOSTED><TRNAMT>-122.10</TRNAMT><NAME>Shop H</NAME></STMTTRN></BANKTRANLIST><LEDGERBAL><BALAMT /><DTASOF /></LEDGERBAL></STMTRS></STMTTRNRS></BANKMSGSRSV1></OFX>
<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><DTSERVER>20181111141713</DTSERVER><LANGUAGE>ENG</LANGUAGE></SONRS></SIGNONMSGSRSV1><BANKMSGSRSV1><STMTTRNRS><TRNUID>0</TRNUID><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><STMTRS><CURDEF>EUR</CURDEF><BANKACCTFROM><BANKID>Revolut</BANKID><ACCTID>Revolut - EUR</ACCTID><ACCTTYPE>CHECKING</ACCTTYPE></BANKACCTFROM><BANKTRANLIST><DTSTART /><DTEND /><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180408</DTPOSTED><TRNAMT>-11.00</TRNAMT><FITID>510fe2b6f621d27915d12e38bacf3668</FITID><NAME>Shop A</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-49.76</TRNAMT><FITID>eac16c811c423955bc657bc070034655</FITID><NAME>Shop B</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-8.00</TRNAMT><FITID>1891409f52283c9155e9650010771446</FITID><NAME>Shop C</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-17.37</TRNAMT><FITID>837c8ac67b261c000bab79b86bdbe9d6</FITID><NAME>Shop D</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180406</DTPOSTED><TRNAMT>-1.95</TRNAMT><FITID>27cb3569e3ed08f0d5f44fbc2ff782f7</FITID><NAME>Shop E</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180405</DTPOSTED><TRNAMT>-5.40</TRNAMT><FITID>efecb957e0db8c75ffcd1d88e6e0f614</FITID><NAME>Shop F</NAME></STMTTRN><STMTTRN><TRNTYPE>DEP</TRNTYPE><DTPOSTED>20180402</DTPOSTED><TRNAMT>200.00</TRNAMT><FITID>5d488b885ed7639cbf2465ba6a7c17fa</FITID><MEMO>Top-Up by *1234</MEMO></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180402</DTPOSTED><TRNAMT>-15.54</TRNAMT><FITID>1f5d35cb7233428c4b3ce7a90cbb886e</FITID><NAME>Shop G</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180401</DTPOSTED><TRNAMT>-122.10</TRNAMT><FITID>da98b7d7611a3e4bd46ab8561f289798</FITID><NAME>Shop H</NAME></STMTTRN></BANKTRANLIST><LEDGERBAL><BALAMT /><DTASOF /></LEDGERBAL></STMTRS></STMTTRNRS></BANKMSGSRSV1></OFX>
2 changes: 1 addition & 1 deletion src/ofxstatement/tests/samples/2019-september.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ OLDFILEUID:NONE
NEWFILEUID:NONE
-->

<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><DTSERVER>20190922141713</DTSERVER><LANGUAGE>ENG</LANGUAGE></SONRS></SIGNONMSGSRSV1><BANKMSGSRSV1><STMTTRNRS><TRNUID>0</TRNUID><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><STMTRS><CURDEF>EUR</CURDEF><BANKACCTFROM><BANKID>Revolut</BANKID><ACCTID>Revolut - EUR</ACCTID><ACCTTYPE>CHECKING</ACCTTYPE></BANKACCTFROM><BANKTRANLIST><DTSTART /><DTEND /><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190915</DTPOSTED><TRNAMT>-21.97</TRNAMT><NAME>Shop A</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190910</DTPOSTED><TRNAMT>-11.62</TRNAMT><NAME>Shop B</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190910</DTPOSTED><TRNAMT>-8.44</TRNAMT><NAME>Shop C</NAME></STMTTRN><STMTTRN><TRNTYPE>DEP</TRNTYPE><DTPOSTED>20190909</DTPOSTED><TRNAMT>200.00</TRNAMT><MEMO>Top-Up by *1234</MEMO></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190908</DTPOSTED><TRNAMT>-58.83</TRNAMT><NAME>Shop D</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190830</DTPOSTED><TRNAMT>-7.95</TRNAMT><NAME>ShopE</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180828</DTPOSTED><TRNAMT>-200.00</TRNAMT><NAME>Exchanged to GBP</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180715</DTPOSTED><TRNAMT>-140.00</TRNAMT><NAME>Exchanged to USD</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180628</DTPOSTED><TRNAMT>140.00</TRNAMT><NAME>Transfer In</NAME></STMTTRN></BANKTRANLIST><LEDGERBAL><BALAMT /><DTASOF /></LEDGERBAL></STMTRS></STMTTRNRS></BANKMSGSRSV1></OFX>
<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><DTSERVER>20190922141713</DTSERVER><LANGUAGE>ENG</LANGUAGE></SONRS></SIGNONMSGSRSV1><BANKMSGSRSV1><STMTTRNRS><TRNUID>0</TRNUID><STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS><STMTRS><CURDEF>EUR</CURDEF><BANKACCTFROM><BANKID>Revolut</BANKID><ACCTID>Revolut - EUR</ACCTID><ACCTTYPE>CHECKING</ACCTTYPE></BANKACCTFROM><BANKTRANLIST><DTSTART /><DTEND /><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190915</DTPOSTED><TRNAMT>-21.97</TRNAMT><FITID>cc03243263eaadf1a96193f9cbf19935</FITID><NAME>Shop A</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190910</DTPOSTED><TRNAMT>-11.62</TRNAMT><FITID>29fff06e117bf015cfbf63c7d7111836</FITID><NAME>Shop B</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190910</DTPOSTED><TRNAMT>-8.44</TRNAMT><FITID>57157647ba43e16c73824356f6fe07c8</FITID><NAME>Shop C</NAME></STMTTRN><STMTTRN><TRNTYPE>DEP</TRNTYPE><DTPOSTED>20190909</DTPOSTED><TRNAMT>200.00</TRNAMT><FITID>559b40a21a6632e109560df081d8c747</FITID><MEMO>Top-Up by *1234</MEMO></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190908</DTPOSTED><TRNAMT>-58.83</TRNAMT><FITID>4ffc84384e2745d2fb520f0e9ec20243</FITID><NAME>Shop D</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20190830</DTPOSTED><TRNAMT>-7.95</TRNAMT><FITID>1cf13d8831b3f75563082d48e2ba8592</FITID><NAME>ShopE</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180828</DTPOSTED><TRNAMT>-200.00</TRNAMT><FITID>dbd38579949cc60a125710a593f24bdd</FITID><NAME>Exchanged to GBP</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180715</DTPOSTED><TRNAMT>-140.00</TRNAMT><FITID>c8117326ec8f3db2db07a2cdd555e134</FITID><NAME>Exchanged to USD</NAME></STMTTRN><STMTTRN><TRNTYPE>POS</TRNTYPE><DTPOSTED>20180628</DTPOSTED><TRNAMT>140.00</TRNAMT><FITID>ecfd00333097f821c09f4043ccf203f6</FITID><NAME>Transfer In</NAME></STMTTRN></BANKTRANLIST><LEDGERBAL><BALAMT /><DTASOF /></LEDGERBAL></STMTRS></STMTTRNRS></BANKMSGSRSV1></OFX>
3 changes: 1 addition & 2 deletions src/ofxstatement/tests/samples/config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[revolut]
plugin = revolut
account = FI1234567890123456
account = Revolut - EUR
currency = EUR
date_format = %%Y-%%m-%%d
16 changes: 8 additions & 8 deletions src/ofxstatement/tests/test_revolut.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

class RevolutTest(unittest.TestCase):

def load_configuration(self):
here = os.path.dirname(__file__)
cfname = os.path.join(here, 'samples', 'config.ini')
return configuration.read(cfname)

def test_configuration(self):
config = self.load_configuration()
self.assertEqual(config['revolut']['date_format'], '%Y-%m-%d')
@classmethod
def setUpClass(cls):
def get_default_location_mock():
current_path = os.path.dirname(os.path.realpath(__file__))
return os.path.join(current_path, 'samples', 'config.ini')

# Use the config.ini found under samples/
configuration.get_default_location = get_default_location_mock

@freeze_time('2018-11-11 14:17:13')
def test_statement_april2018(self):
Expand Down

0 comments on commit 6f1e598

Please sign in to comment.