Fix whitespaces in new revolut format

This commit is contained in:
Gabriel Augendre 2021-09-17 14:16:16 +02:00
parent 6577f7e84e
commit eb629a9a4f
5 changed files with 41 additions and 19 deletions

View file

@ -1,4 +1,5 @@
import csv
import re
import sys
import click
@ -7,9 +8,11 @@ import dateparser
from ofx_processor.utils.base_processor import BaseProcessor, BaseLine
def _amount_str_to_float(amount):
def _amount_str_to_float(amount: str):
if amount:
return float(amount.replace(",", "."))
amount = amount.replace(",", ".")
amount = re.sub(r"\s+", "", amount)
return float(amount)
return ""

View file

@ -1,10 +1,11 @@
Completed Date;Reference;Paid Out (EUR);Paid In (EUR);Exchange Out;Exchange In; Balance (EUR);Exchange Rate;Category
29 Jan;To Person 1;53,63;;;;21,66; ;Transfers
29 Jan;To Person 2;0,90;;;;75,29; ;Transfers
29 Jan;Refund from Company 2;;53,63;;;76,19; ;Shopping
24 Jan;To Person 3;8,50;;;;22,56; ;Transfers
16 Jan;To Person 4;1,40;;;;31,06; ;Transfers
10 Jan;To Person 5;2,01;;;;32,46; ;Transfers
10 Jan;To Person 6;1,21;;;;34,47; ;Transfers
5 Jan;Company 1;123,68;;USD 138,00;;35,68;FX-rate €1=US$1,1158;Shopping
4 Jan;Top-up via Apple Pay;;100,00;;;159,36; ;General
30 août 2021;Virement de NAME;;1500,00 ;;;1521,66 ; ;Transferts
29 Jan 2020;To Person 1;53,63;;;;21,66; ;Transfers
29 Jan 2020;To Person 2;0,90;;;;75,29; ;Transfers
29 Jan 2020;Refund from Company 2;;53,63;;;76,19; ;Shopping
24 Jan 2020;To Person 3;8,50;;;;22,56; ;Transfers
16 Jan 2020;To Person 4;1,40;;;;31,06; ;Transfers
10 Jan 2020;To Person 5;2,01;;;;32,46; ;Transfers
10 Jan 2020;To Person 6;1,21;;;;34,47; ;Transfers
5 Jan 2020;Company 1;123,68;;USD 138,00;;35,68;FX-rate €1=US$1,1158;Shopping
4 Jan 2020;Top-up via Apple Pay;;100,00;;;159,36; ;General

1 Completed Date Reference Paid Out (EUR) Paid In (EUR) Exchange Out Exchange In Balance (EUR) Exchange Rate Category
2 29 Jan 30 août 2021 To Person 1 Virement de NAME 53,63 1 500,00  21,66 1 521,66  Transfers Transferts
3 29 Jan 29 Jan 2020 To Person 2 To Person 1 0,90 53,63 75,29 21,66 Transfers
4 29 Jan 29 Jan 2020 Refund from Company 2 To Person 2 0,90 53,63 76,19 75,29 Shopping Transfers
5 24 Jan 29 Jan 2020 To Person 3 Refund from Company 2 8,50 53,63 22,56 76,19 Transfers Shopping
6 16 Jan 24 Jan 2020 To Person 4 To Person 3 1,40 8,50 31,06 22,56 Transfers
7 10 Jan 16 Jan 2020 To Person 5 To Person 4 2,01 1,40 32,46 31,06 Transfers
8 10 Jan 10 Jan 2020 To Person 6 To Person 5 1,21 2,01 34,47 32,46 Transfers
9 5 Jan 10 Jan 2020 Company 1 To Person 6 123,68 1,21 USD 138,00 35,68 34,47 FX-rate €1 = US$1,1158 Shopping Transfers
10 4 Jan 5 Jan 2020 Top-up via Apple Pay Company 1 123,68 100,00 USD 138,00 159,36 35,68 FX-rate €1 = US$1,1158 General Shopping
11 4 Jan 2020 Top-up via Apple Pay 100,00 159,36 General

View file

@ -1,4 +1,11 @@
[
{
"date": "2021-08-30",
"amount": 1500000,
"payee_name": "Virement de NAME",
"memo": "Transferts",
"import_id": "YNAB:1500000:2021-08-30:1"
},
{
"date": "2020-01-29",
"amount": -53630,
@ -62,4 +69,4 @@
"memo": "General",
"import_id": "YNAB:100000:2020-01-04:1"
}
]
]

View file

@ -1,5 +1,13 @@
{
"transactions": [
{
"date": "2021-08-30",
"amount": 1500000,
"payee_name": "Virement de NAME",
"memo": "Transferts",
"import_id": "YNAB:1500000:2021-08-30:1",
"account_id": "<YOUR REVOLUT ACCOUNT ID>"
},
{
"date": "2020-01-29",
"amount": -53630,

View file

@ -77,7 +77,7 @@ class ConfigTestCase(unittest.TestCase):
self.cli, ["revolut", "tests/samples/revolut.csv", "--keep"]
)
expected_filename = ynab.get_config_file_name()
self.assertIn("Error while parsing config file", result.output)
self.assertIn("Error while parsing config file", result.output, f"config_file: {name}")
edit.assert_called_with(filename=expected_filename)
@mock.patch("ofx_processor.utils.ynab.DEFAULT_CONFIG_FILENAME", "file.ini")
@ -187,6 +187,7 @@ class DataTestCase(unittest.TestCase):
{"id": "created:9", "matched_transaction_id": None},
{"id": "created:10", "matched_transaction_id": None},
{"id": "created:11", "matched_transaction_id": None},
{"id": "created:12", "matched_transaction_id": None},
],
"duplicate_import_ids": [],
}
@ -198,8 +199,8 @@ class DataTestCase(unittest.TestCase):
)
self.assertEqual(result.exit_code, 0)
self.assertIn("Processed 9 transactions total.", result.output)
self.assertIn("9 transactions created in YNAB.", result.output)
self.assertIn("Processed 10 transactions total.", result.output)
self.assertIn("10 transactions created in YNAB.", result.output)
self.assertNotIn("transactions ignored (duplicates).", result.output)
@mock.patch("requests.post")
@ -232,6 +233,7 @@ class DataTestCase(unittest.TestCase):
"duplicate:9",
"duplicate:10",
"duplicate:11",
"duplicate:12",
],
}
}
@ -242,9 +244,9 @@ class DataTestCase(unittest.TestCase):
)
self.assertEqual(result.exit_code, 0)
self.assertIn("Processed 9 transactions total.", result.output)
self.assertIn("Processed 10 transactions total.", result.output)
self.assertIn("3 transactions created in YNAB.", result.output)
self.assertIn("6 transactions ignored (duplicates).", result.output)
self.assertIn("7 transactions ignored (duplicates).", result.output)
@mock.patch("requests.post")
def test_revolut_sends_data_only_duplicates(self, post):
@ -261,6 +263,7 @@ class DataTestCase(unittest.TestCase):
"duplicate:7",
"duplicate:8",
"duplicate:9",
"duplicate:10",
],
}
}
@ -271,9 +274,9 @@ class DataTestCase(unittest.TestCase):
)
self.assertEqual(result.exit_code, 0)
self.assertIn("Processed 9 transactions total.", result.output)
self.assertIn("Processed 10 transactions total.", result.output)
self.assertNotIn("transactions created in YNAB.", result.output)
self.assertIn("9 transactions ignored (duplicates).", result.output)
self.assertIn("10 transactions ignored (duplicates).", result.output)
@mock.patch("requests.post")
def test_bpvf_sends_to_ynab(self, post):