Skip to content

Commit

Permalink
[FIX] Version 2.0.2: Don't crash if the statement contains pending tr…
Browse files Browse the repository at this point in the history
…ansactions. Ignore them instead.
  • Loading branch information
mlaitinen committed Jan 22, 2022
1 parent fde6270 commit bfb633e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.0.2
-----
- Ignore other than COMPLETED transactions. Pending transactions have their own structure in OFX
called STMTTRNP, but ofxstatement doesn't support it.
- Include the "Started Date" as the date the user initiated the transaction.

2.0.1
-----
- Version 2.0.0 republished due to some issues with PyPI
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 = "2.0.1"
version = "2.0.2"

setup(name="ofxstatement-revolut",
version=version,
Expand Down
7 changes: 7 additions & 0 deletions src/ofxstatement/plugins/revolut.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class RevolutCSVStatementParser(CsvStatementParser):

mappings = {
"trntype": 0,
"date_user": 2,
"date": 3,
"payee": 4,
"amount": 5,
Expand All @@ -49,6 +50,11 @@ def parse_record(self, line: List[str]) -> Optional[StatementLine]:
return None

c = self.columns

# Ignore pending charges
if line[c["State"]] != "COMPLETED":
return None

stmt_line = super().parse_record(line)

# Generate a unique ID
Expand Down Expand Up @@ -93,6 +99,7 @@ def get_parser(self, filename: str) -> RevolutCSVStatementParser:
csv_columns = [col.strip() for col in signature.split(",")]
required_columns = [
"Type",
"Started Date",
"Completed Date",
"Description",
"Amount",
Expand Down
10 changes: 10 additions & 0 deletions tests/samples/2022-january.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Type,Product,Started Date,Completed Date,Description,Amount,Fee,Currency,State,Balance
TRANSFER,Current,2022-01-02 12:16:54,2022-01-02 12:16:55,To Guybrush Threepwood,-250.00,0.00,EUR,COMPLETED,442.67
CARD_PAYMENT,Current,2022-01-06 15:08:08,2022-01-06 15:08:08,Google *temporary Hold,0.00,0.00,EUR,COMPLETED,420.74
CARD_PAYMENT,Current,2022-01-06 08:40:02,2022-01-07 10:28:09,"Something and something",-38.71,0.00,EUR,COMPLETED,223.53
TOPUP,Current,2022-01-08 08:11:42,2022-01-08 08:12:12,Top-Up by *1234,500.00,0.00,EUR,COMPLETED,723.53
CARD_PAYMENT,Current,2022-01-09 16:35:04,2022-01-10 14:51:42,Rimi,-21.58,0.00,EUR,COMPLETED,425.68
CARD_PAYMENT,Current,2022-01-13 11:21:43,,store,-44.57,0.00,EUR,PENDING,
CARD_PAYMENT,Current,2022-01-13 16:52:43,2022-01-14 08:22:37,food,-33.89,0.00,EUR,COMPLETED,1909.52
CARD_PAYMENT,Current,2022-01-13 11:30:07,2022-01-14 09:16:48,www.example.com,-69.26,0.00,EUR,COMPLETED,1840.26
CARD_PAYMENT,Current,2022-01-15 11:30:37,,www.pending.com,-73.58,0.00,EUR,PENDING,
19 changes: 19 additions & 0 deletions tests/test_revolut.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,22 @@ def test_revolut_simple() -> None:
assert line1.payee == "company äöå"
assert line1.trntype == "POS"
assert line1.id == "b611755c1f6a53241aec217791399302"


def test_revolut_ignore_pending() -> None:
plugin = RevolutPlugin(UI(), {})
filename = os.path.join(HERE, "samples", "2022-january.csv")

parser = plugin.get_parser(filename)
statement = parser.parse()

assert len(statement.lines) == 7

line0 = statement.lines[2]
assert line0.amount == Decimal("-38.71")
assert line0.currency.symbol == "EUR"
assert line0.date_user == datetime.datetime(2022, 1, 6, 8, 40, 2)
assert line0.date == datetime.datetime(2022, 1, 7, 10, 28, 9)
assert line0.payee == "Something and something"
assert line0.trntype == "POS"
assert line0.id == "a6563f2732189f992f8439ac549fd6bc"

0 comments on commit bfb633e

Please sign in to comment.