From bfb633e25ef89e0a808bc6ee53f77fc1a30be1a1 Mon Sep 17 00:00:00 2001 From: Miku Laitinen Date: Sat, 22 Jan 2022 12:47:42 +0200 Subject: [PATCH] [FIX] Version 2.0.2: Don't crash if the statement contains pending transactions. Ignore them instead. --- docs/HISTORY.txt | 6 ++++++ setup.py | 2 +- src/ofxstatement/plugins/revolut.py | 7 +++++++ tests/samples/2022-january.csv | 10 ++++++++++ tests/test_revolut.py | 19 +++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/samples/2022-january.csv diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index d45d034..abbfbfb 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -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 diff --git a/setup.py b/setup.py index fc081a4..1e17950 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ import unittest -version = "2.0.1" +version = "2.0.2" setup(name="ofxstatement-revolut", version=version, diff --git a/src/ofxstatement/plugins/revolut.py b/src/ofxstatement/plugins/revolut.py index 792ef5e..c5e7626 100644 --- a/src/ofxstatement/plugins/revolut.py +++ b/src/ofxstatement/plugins/revolut.py @@ -23,6 +23,7 @@ class RevolutCSVStatementParser(CsvStatementParser): mappings = { "trntype": 0, + "date_user": 2, "date": 3, "payee": 4, "amount": 5, @@ -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 @@ -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", diff --git a/tests/samples/2022-january.csv b/tests/samples/2022-january.csv new file mode 100644 index 0000000..d2a5423 --- /dev/null +++ b/tests/samples/2022-january.csv @@ -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, diff --git a/tests/test_revolut.py b/tests/test_revolut.py index 7a89199..4087132 100644 --- a/tests/test_revolut.py +++ b/tests/test_revolut.py @@ -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"