tariochbctools 1.5.0__tar.gz → 1.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/PKG-INFO +1 -1
  2. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/postfinance/importer.py +3 -2
  3. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/truelayer/importer.py +60 -32
  4. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/PKG-INFO +1 -1
  5. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/SOURCES.txt +1 -0
  6. tariochbctools-1.5.2/tests/tariochbctools/importers/test_postfinance.py +46 -0
  7. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/importers/test_truelayer.py +50 -9
  8. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/.coveragerc +0 -0
  9. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/.isort.cfg +0 -0
  10. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/.pre-commit-config.yaml +0 -0
  11. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/.readthedocs.yml +0 -0
  12. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/LICENSE.txt +0 -0
  13. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/MANIFEST.in +0 -0
  14. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/README.rst +0 -0
  15. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/_static/.gitignore +0 -0
  16. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/conf.py +0 -0
  17. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/importers.rst +0 -0
  18. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/index.rst +0 -0
  19. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/installation.rst +0 -0
  20. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/license.rst +0 -0
  21. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/plugins.rst +0 -0
  22. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/price_fetchers.rst +0 -0
  23. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/docs/requirements.txt +0 -0
  24. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/pyproject.toml +0 -0
  25. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/setup.cfg +0 -0
  26. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/setup.py +0 -0
  27. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/__init__.py +0 -0
  28. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/__init__.py +0 -0
  29. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/awardwalletimp/__init__.py +0 -0
  30. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/awardwalletimp/config.py +0 -0
  31. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/awardwalletimp/importer.py +0 -0
  32. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/bcge/__init__.py +0 -0
  33. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/bcge/importer.py +0 -0
  34. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/bitst/__init__.py +0 -0
  35. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/bitst/importer.py +0 -0
  36. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/blockchain/__init__.py +0 -0
  37. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/blockchain/importer.py +0 -0
  38. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/cembrastatement/__init__.py +0 -0
  39. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/cembrastatement/importer.py +0 -0
  40. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/general/__init__.py +0 -0
  41. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/general/deduplication.py +0 -0
  42. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/general/mailAdapterImporter.py +0 -0
  43. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/general/mt940importer.py +0 -0
  44. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/general/priceLookup.py +0 -0
  45. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/ibkr/__init__.py +0 -0
  46. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/ibkr/importer.py +0 -0
  47. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/neon/__init__.py +0 -0
  48. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/neon/importer.py +0 -0
  49. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/netbenefits/__init__.py +0 -0
  50. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/netbenefits/importer.py +0 -0
  51. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/nordigen/__init__.py +0 -0
  52. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/nordigen/importer.py +0 -0
  53. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/nordigen/nordigen_config.py +0 -0
  54. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/postfinance/__init__.py +0 -0
  55. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/quickfile/__init__.py +0 -0
  56. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/quickfile/importer.py +0 -0
  57. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/radicant/__init__.py +0 -0
  58. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/radicant/importer.py +0 -0
  59. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/raiffeisench/importer.py +0 -0
  60. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/revolut/__init__.py +0 -0
  61. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/revolut/importer.py +0 -0
  62. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/schedule/__init__.py +0 -0
  63. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/schedule/importer.py +0 -0
  64. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/swisscard/__init__.py +0 -0
  65. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/swisscard/importer.py +0 -0
  66. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/transferwise/__init__.py +0 -0
  67. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/transferwise/importer.py +0 -0
  68. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/truelayer/__init__.py +0 -0
  69. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/viseca/__init__.py +0 -0
  70. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/viseca/importer.py +0 -0
  71. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/zak/__init__.py +0 -0
  72. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/zak/importer.py +0 -0
  73. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/zkb/__init__.py +0 -0
  74. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/importers/zkb/importer.py +0 -0
  75. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/plugins/__init__.py +0 -0
  76. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/plugins/check_portfolio_sum.py +0 -0
  77. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/plugins/generate_base_ccy_prices.py +0 -0
  78. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/plugins/prices/__init__.py +0 -0
  79. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools/plugins/prices/ibkr.py +0 -0
  80. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/dependency_links.txt +0 -0
  81. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/entry_points.txt +0 -0
  82. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/not-zip-safe +0 -0
  83. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/requires.txt +0 -0
  84. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/src/tariochbctools.egg-info/top_level.txt +0 -0
  85. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/__init__.py +0 -0
  86. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/conftest.py +0 -0
  87. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/__init__.py +0 -0
  88. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/importers/__init__.py +0 -0
  89. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/importers/test_awardwallet.py +0 -0
  90. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/importers/test_quickfile.py +0 -0
  91. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/__init__.py +0 -0
  92. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/entry_already_exists_expected.beancount +0 -0
  93. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/entry_already_exists_input.beancount +0 -0
  94. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/issue122_expected.beancount +0 -0
  95. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/issue122_input.beancount +0 -0
  96. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/missing_fx_expected.beancount +0 -0
  97. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/missing_fx_input.beancount +0 -0
  98. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/normal_expected.beancount +0 -0
  99. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/data/generate_base_ccy_prices/normal_input.beancount +0 -0
  100. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tests/tariochbctools/plugins/test_generate_base_ccy_prices.py +0 -0
  101. {tariochbctools-1.5.0 → tariochbctools-1.5.2}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tariochbctools
3
- Version: 1.5.0
3
+ Version: 1.5.2
4
4
  Summary: Importers, plugins and price fetchers for Beancount
5
5
  Home-page: https://github.com/tarioch/beancounttools/
6
6
  Author: Patrick Ruckstuhl
@@ -1,10 +1,11 @@
1
1
  import csv
2
2
  import logging
3
3
  import re
4
- from datetime import datetime, timedelta
4
+ from datetime import timedelta
5
5
  from decimal import Decimal
6
6
 
7
7
  import beangulp
8
+ import dateutil.parser
8
9
  from beancount.core import data
9
10
 
10
11
 
@@ -31,7 +32,7 @@ class Importer(beangulp.Importer):
31
32
  for row in reader:
32
33
  try:
33
34
  book_date_str, text, credit, debit, val_date, balance_str = tuple(row)
34
- book_date = datetime.strptime(book_date_str, "%Y-%m-%d").date()
35
+ book_date = dateutil.parser.parse(book_date_str).date()
35
36
  if credit:
36
37
  amount = data.Amount(Decimal(credit), self.currency)
37
38
  elif debit:
@@ -10,6 +10,8 @@ import yaml
10
10
  from beancount.core import amount, data
11
11
  from beancount.core.number import D
12
12
 
13
+ from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator
14
+
13
15
  # https://docs.truelayer.com/#retrieve-account-transactions
14
16
 
15
17
  TX_MANDATORY_ID_FIELDS = ("transaction_id",)
@@ -125,6 +127,17 @@ class Importer(beangulp.Importer):
125
127
  logging.warning("Ignoring account ID %s", accountId)
126
128
  continue
127
129
 
130
+ r = requests.get(
131
+ f"https://api.{self.domain}/data/v1/{endpoint}/{accountId}/balance",
132
+ headers=headers,
133
+ )
134
+ balances = r.json()["results"]
135
+
136
+ for balance in balances:
137
+ entries.extend(
138
+ self._extract_balance(balance, local_account, invert_sign)
139
+ )
140
+
128
141
  r = requests.get(
129
142
  f"https://api.{self.domain}/data/v1/{endpoint}/{accountId}/transactions",
130
143
  headers=headers,
@@ -148,7 +161,7 @@ class Importer(beangulp.Importer):
148
161
  invert_sign: bool,
149
162
  ) -> data.Transaction:
150
163
  entries = []
151
- metakv = {}
164
+ metakv: dict[str, Any] = {}
152
165
 
153
166
  id_meta_kvs = {
154
167
  k: trx["meta"][k] for k in TX_OPTIONAL_META_ID_FIELDS if trx["meta"].get(k)
@@ -193,37 +206,52 @@ class Importer(beangulp.Importer):
193
206
  )
194
207
  entries.append(entry)
195
208
 
196
- if trx["transaction_id"] == transactions[-1]["transaction_id"]:
197
- balDate = trxDate + timedelta(days=1)
198
- metakv = {}
199
- if self.existing is not None:
200
- for exEntry in self.existing:
201
- if (
202
- isinstance(exEntry, data.Balance)
203
- and exEntry.date == balDate
204
- and exEntry.account == local_account
205
- ):
206
- metakv["__duplicate__"] = True
207
-
208
- meta = data.new_metadata("", 0, metakv)
209
-
210
- # Only if the 'balance' permission is present
211
- if "running_balance" in trx:
212
- tx_balance = D(str(trx["running_balance"]["amount"]))
213
- # avoid pylint invalid-unary-operand-type
214
- signed_balance = -1 * tx_balance if invert_sign else tx_balance
215
-
216
- entries.append(
217
- data.Balance(
218
- meta,
219
- balDate,
220
- local_account,
221
- amount.Amount(
222
- signed_balance, trx["running_balance"]["currency"]
223
- ),
224
- None,
225
- None,
226
- )
209
+ return entries
210
+
211
+ def _extract_balance(
212
+ self,
213
+ result: dict[str, Any],
214
+ local_account: data.Account,
215
+ invert_sign: bool,
216
+ ) -> data.Transaction:
217
+ entries = []
218
+
219
+ meta = data.new_metadata("", 0)
220
+
221
+ balance = D(str(result["current"]))
222
+ # avoid pylint invalid-unary-operand-type
223
+ signed_balance = -1 * balance if invert_sign else balance
224
+ balance_date = dateutil.parser.parse(result["update_timestamp"]).date()
225
+
226
+ entries.append(
227
+ data.Balance(
228
+ meta,
229
+ balance_date + timedelta(days=1),
230
+ local_account,
231
+ amount.Amount(signed_balance, result["currency"]),
232
+ None,
233
+ None,
234
+ )
235
+ )
236
+
237
+ if "last_statement_balance" in result:
238
+ statement_balance = D(str(result["last_statement_balance"]))
239
+ signed_statement_balance = (
240
+ -1 * statement_balance if invert_sign else statement_balance
241
+ )
242
+ statement_date = dateutil.parser.parse(result["last_statement_date"]).date()
243
+
244
+ entries.append(
245
+ data.Balance(
246
+ meta,
247
+ statement_date,
248
+ local_account,
249
+ amount.Amount(signed_statement_balance, result["currency"]),
250
+ None,
251
+ None,
227
252
  )
253
+ )
228
254
 
229
255
  return entries
256
+
257
+ cmp = ReferenceDuplicatesComparator(TX_MANDATORY_ID_FIELDS)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tariochbctools
3
- Version: 1.5.0
3
+ Version: 1.5.2
4
4
  Summary: Importers, plugins and price fetchers for Beancount
5
5
  Home-page: https://github.com/tarioch/beancounttools/
6
6
  Author: Patrick Ruckstuhl
@@ -85,6 +85,7 @@ tests/conftest.py
85
85
  tests/tariochbctools/__init__.py
86
86
  tests/tariochbctools/importers/__init__.py
87
87
  tests/tariochbctools/importers/test_awardwallet.py
88
+ tests/tariochbctools/importers/test_postfinance.py
88
89
  tests/tariochbctools/importers/test_quickfile.py
89
90
  tests/tariochbctools/importers/test_truelayer.py
90
91
  tests/tariochbctools/plugins/__init__.py
@@ -0,0 +1,46 @@
1
+ import pytest
2
+ from beancount.core.amount import Amount
3
+ from beancount.core.number import D
4
+
5
+ from tariochbctools.importers.postfinance import importer as pfimp
6
+
7
+ TEST_CSV = """
8
+ Booking date;Notification text;Credit in CHF;Debit in CHF;Value;Balance in CHF
9
+ 31.12.2022;"Preis für Bankpaket Smart";;-5;31.12.2022;7881.98
10
+ """
11
+
12
+ TEST_CSV_2021 = """
13
+ Booking date;Notification text;Credit in CHF;Debit in CHF;Value;Balance in CHF
14
+ 2022-12-31;"Preis für Bankpaket Smart";;-5;2022-12-31;7881.98
15
+ """
16
+
17
+
18
+ @pytest.fixture(name="importer")
19
+ def importer_fixture():
20
+ importer = pfimp.Importer(".*.csv", "Assets:PostFinance:CHF")
21
+ yield importer
22
+
23
+
24
+ @pytest.fixture
25
+ def tmp_csv(tmp_path, request):
26
+ csv = tmp_path / "test.csv"
27
+ csv.write_text(request.param)
28
+ yield csv
29
+
30
+
31
+ @pytest.mark.parametrize("tmp_csv", [TEST_CSV], indirect=True)
32
+ def test_identify(importer, tmp_csv):
33
+ assert importer.identify(str(tmp_csv))
34
+
35
+
36
+ @pytest.mark.parametrize(
37
+ "tmp_csv",
38
+ (TEST_CSV, TEST_CSV_2021),
39
+ ids=("dd.mm.yyyy", "yyyy-mm-dd"),
40
+ indirect=True,
41
+ )
42
+ def test_extract(importer, tmp_csv):
43
+ entries = importer.extract(str(tmp_csv), [])
44
+ assert entries
45
+ assert entries[0].postings[-1].units == Amount(D(-5), "CHF")
46
+ assert entries[0].date.year == 2022
@@ -1,5 +1,7 @@
1
1
  import json
2
+ from datetime import timedelta
2
3
 
4
+ import dateutil.parser
3
5
  import pytest
4
6
  import yaml
5
7
  from beancount.core.amount import Decimal as D
@@ -67,6 +69,28 @@ TEST_TRX_WITHOUT_IDS = b"""
67
69
  }
68
70
  """
69
71
 
72
+ TEST_BALANCE_SIMPLE = b"""
73
+ {
74
+ "currency": "GBP",
75
+ "current": 20.0,
76
+ "update_timestamp": "2017-02-24T17:29:24.740Z"
77
+ }
78
+ """
79
+
80
+ TEST_BALANCE_OPTIONAL = b"""
81
+ {
82
+ "available": 3279.0,
83
+ "currency": "GBP",
84
+ "current": 20.0,
85
+ "credit_limit": 3300,
86
+ "last_statement_balance": 226,
87
+ "last_statement_date": "2017-01-28",
88
+ "payment_due": 5.0,
89
+ "payment_due_date": "2017-02-24",
90
+ "update_timestamp": "2017-02-24T17:29:24.740Z"
91
+ }
92
+ """
93
+
70
94
 
71
95
  @pytest.fixture(name="tmp_config")
72
96
  def tmp_config_fixture(tmp_path):
@@ -114,15 +138,6 @@ def test_extract_transaction_simple(importer, tmp_trx):
114
138
  assert entries[0].postings[0].units.number == D(str(tmp_trx["amount"]))
115
139
 
116
140
 
117
- def test_extract_transaction_with_balance(importer, tmp_trx):
118
- entries = importer._extract_transaction(
119
- tmp_trx, "Assets:Other", [tmp_trx], invert_sign=False
120
- )
121
- # one entry, one balance
122
- assert len(entries) == 2
123
- assert entries[1].amount.number == D(str(tmp_trx["running_balance"]["amount"]))
124
-
125
-
126
141
  def test_extract_transaction_invert_sign(importer, tmp_trx):
127
142
  """Show that sign inversion works"""
128
143
  entries = importer._extract_transaction(
@@ -131,6 +146,32 @@ def test_extract_transaction_invert_sign(importer, tmp_trx):
131
146
  assert entries[0].postings[0].units.number == -D(str(tmp_trx["amount"]))
132
147
 
133
148
 
149
+ def test_extract_balance(importer, tmp_trx):
150
+ tmp_balance = json.loads(TEST_BALANCE_SIMPLE)
151
+
152
+ entries = importer._extract_balance(tmp_balance, "Assets:Other", invert_sign=False)
153
+
154
+ assert len(entries) == 1
155
+ assert entries[-1].amount.number == D(str(tmp_balance["current"]))
156
+ assert (
157
+ entries[-1].date - timedelta(days=1)
158
+ == dateutil.parser.parse(tmp_balance["update_timestamp"]).date()
159
+ ), "balance date should be one day after update_timestamp"
160
+
161
+
162
+ def test_extract_statement_balance(importer, tmp_trx):
163
+ tmp_balance = json.loads(TEST_BALANCE_OPTIONAL)
164
+
165
+ entries = importer._extract_balance(tmp_balance, "Assets:Other", invert_sign=False)
166
+
167
+ assert len(entries) == 2
168
+ assert entries[-1].amount.number == D(str(tmp_balance["last_statement_balance"]))
169
+ assert (
170
+ entries[-1].date
171
+ == dateutil.parser.parse(tmp_balance["last_statement_date"]).date()
172
+ )
173
+
174
+
134
175
  @pytest.mark.parametrize("id_field", tlimp.TX_MANDATORY_ID_FIELDS)
135
176
  def test_extract_transaction_has_transaction_id(importer, tmp_trx, id_field):
136
177
  """Ensure mandatory IDs are in extracted transactions."""
File without changes
File without changes
File without changes