aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--beancount_extras_kris7t/importers/otpbank/otpbank_csv.py3
-rw-r--r--beancount_extras_kris7t/importers/transferwise/__main__.py2
-rw-r--r--beancount_extras_kris7t/importers/transferwise/client.py12
-rw-r--r--beancount_extras_kris7t/importers/transferwise/transferwise_json.py2
-rw-r--r--beancount_extras_kris7t/plugins/selective_implicit_prices.py11
-rw-r--r--mypy.ini6
6 files changed, 24 insertions, 12 deletions
diff --git a/beancount_extras_kris7t/importers/otpbank/otpbank_csv.py b/beancount_extras_kris7t/importers/otpbank/otpbank_csv.py
index 9e12ec3..c0f66ba 100644
--- a/beancount_extras_kris7t/importers/otpbank/otpbank_csv.py
+++ b/beancount_extras_kris7t/importers/otpbank/otpbank_csv.py
@@ -236,7 +236,8 @@ def extract_foreign_currencies(
236 236
237def extract_cards(card_accounts: Dict[str, str]) -> Extractor: 237def extract_cards(card_accounts: Dict[str, str]) -> Extractor:
238 def do_extract(row: Row) -> None: 238 def do_extract(row: Row) -> None:
239 if row.entry_type.lower() not in [ 239 entry_type = row.entry_type
240 if not entry_type or entry_type.lower() not in [
240 'vásárlás kártyával', 241 'vásárlás kártyával',
241 'bankkártyával kapcs. díj', 242 'bankkártyával kapcs. díj',
242 ]: 243 ]:
diff --git a/beancount_extras_kris7t/importers/transferwise/__main__.py b/beancount_extras_kris7t/importers/transferwise/__main__.py
index e25580d..4ac2058 100644
--- a/beancount_extras_kris7t/importers/transferwise/__main__.py
+++ b/beancount_extras_kris7t/importers/transferwise/__main__.py
@@ -4,7 +4,7 @@ Importer for Transferwise API transaction history.
4__copyright__ = 'Copyright (c) 2020 Kristóf Marussy <kristof@marussy.com>' 4__copyright__ = 'Copyright (c) 2020 Kristóf Marussy <kristof@marussy.com>'
5__license__ = 'GNU GPLv2' 5__license__ = 'GNU GPLv2'
6 6
7from importers.transferwise.client import main 7from beancount_extras_kris7t.importers.transferwise.client import main
8 8
9 9
10if __name__ == '__main__': 10if __name__ == '__main__':
diff --git a/beancount_extras_kris7t/importers/transferwise/client.py b/beancount_extras_kris7t/importers/transferwise/client.py
index a4b6629..5198122 100644
--- a/beancount_extras_kris7t/importers/transferwise/client.py
+++ b/beancount_extras_kris7t/importers/transferwise/client.py
@@ -25,8 +25,8 @@ def _parse_date_arg(date_str: str) -> dt.date:
25def _import_config(config_path: str) -> Importer: 25def _import_config(config_path: str) -> Importer:
26 import runpy 26 import runpy
27 27
28 config = runpy.run_path(config_path) 28 config = runpy.run_path(config_path) # type: ignore
29 importer = config['TRANSFERWISE_CONFIG'] # type: ignore 29 importer = config['TRANSFERWISE_CONFIG']
30 if isinstance(importer, Importer): 30 if isinstance(importer, Importer):
31 LOG.info('Loaded configuration from %s', config_path) 31 LOG.info('Loaded configuration from %s', config_path)
32 return importer 32 return importer
@@ -65,7 +65,7 @@ def _get_last_transaction_date(ledger_path: str, skip_references: Set[str]) -> O
65def _get_date_range(from_date: Optional[dt.date], 65def _get_date_range(from_date: Optional[dt.date],
66 to_date: dt.date, 66 to_date: dt.date,
67 ledger_path: Optional[str]) -> Tuple[dt.date, dt.date, Set[str]]: 67 ledger_path: Optional[str]) -> Tuple[dt.date, dt.date, Set[str]]:
68 skip_references = set() 68 skip_references: Set[str] = set()
69 if not from_date and ledger_path: 69 if not from_date and ledger_path:
70 from_date = _get_last_transaction_date(ledger_path, skip_references) 70 from_date = _get_last_transaction_date(ledger_path, skip_references)
71 if not from_date: 71 if not from_date:
@@ -79,6 +79,7 @@ def _get_secrets(importer: Importer,
79 proxy_uri: Optional[str]) -> Tuple[str, Optional[str]]: 79 proxy_uri: Optional[str]) -> Tuple[str, Optional[str]]:
80 import urllib.parse 80 import urllib.parse
81 81
82 uri_parts: Optional[urllib.parse.SplitResult]
82 if proxy_uri: 83 if proxy_uri:
83 uri_parts = urllib.parse.urlsplit(proxy_uri) 84 uri_parts = urllib.parse.urlsplit(proxy_uri)
84 else: 85 else:
@@ -122,7 +123,7 @@ def _get_secrets(importer: Importer,
122 proxy_uri = uri 123 proxy_uri = uri
123 else: 124 else:
124 LOG.info('No proxy password secret was found in SecretService') 125 LOG.info('No proxy password secret was found in SecretService')
125 assert api_key # Make pyright happy 126 assert api_key # Make mypy happy
126 return api_key, proxy_uri 127 return api_key, proxy_uri
127 128
128 129
@@ -141,8 +142,9 @@ def _fetch_statements(importer: Importer,
141 uri_prefix = f'https://api.transferwise.com/v3/profiles/{importer.profile_id}/' + \ 142 uri_prefix = f'https://api.transferwise.com/v3/profiles/{importer.profile_id}/' + \
142 f'borderless-accounts/{importer.borderless_account_id}/statement.json' + \ 143 f'borderless-accounts/{importer.borderless_account_id}/statement.json' + \
143 f'?intervalStart={from_time_str}&intervalEnd={to_time_str}&type=COMPACT&currency=' 144 f'?intervalStart={from_time_str}&intervalEnd={to_time_str}&type=COMPACT&currency='
145 beancount_version = beancount.__version__ # type: ignore # noqa: unused-type-ignore
144 headers = { 146 headers = {
145 'User-Agent': f'Beancount {beancount.__version__} Transferwise importer {__copyright__}', 147 'User-Agent': f'Beancount {beancount_version} Transferwise importer {__copyright__}',
146 'Authorization': f'Bearer {api_key}', 148 'Authorization': f'Bearer {api_key}',
147 } 149 }
148 proxy_dict: Dict[str, str] = {} 150 proxy_dict: Dict[str, str] = {}
diff --git a/beancount_extras_kris7t/importers/transferwise/transferwise_json.py b/beancount_extras_kris7t/importers/transferwise/transferwise_json.py
index c42de90..68ddc6d 100644
--- a/beancount_extras_kris7t/importers/transferwise/transferwise_json.py
+++ b/beancount_extras_kris7t/importers/transferwise/transferwise_json.py
@@ -211,6 +211,8 @@ class Row(utils.Row):
211 # Also add the "fudge" amounts to the fees generated by rounding currency conversions. 211 # Also add the "fudge" amounts to the fees generated by rounding currency conversions.
212 all_fees = Inventory() 212 all_fees = Inventory()
213 all_fees.add_inventory(self._fees) 213 all_fees.add_inventory(self._fees)
214 if not self.postings:
215 raise InvalidEntry('Trying to create transaction without postings')
214 for acc, assigned_units in self.postings: 216 for acc, assigned_units in self.postings:
215 for conversion in self._conversions: 217 for conversion in self._conversions:
216 units, price, fudge = conversion.get_fraction( 218 units, price, fudge = conversion.get_fraction(
diff --git a/beancount_extras_kris7t/plugins/selective_implicit_prices.py b/beancount_extras_kris7t/plugins/selective_implicit_prices.py
index 07dc893..8f5186d 100644
--- a/beancount_extras_kris7t/plugins/selective_implicit_prices.py
+++ b/beancount_extras_kris7t/plugins/selective_implicit_prices.py
@@ -9,7 +9,9 @@ __copyright__ = "Copyright (C) 2015-2017 Martin Blais, " + \
9__license__ = "GNU GPLv2" 9__license__ = "GNU GPLv2"
10 10
11import collections 11import collections
12from typing import List, Tuple, Set 12import datetime as dt
13from decimal import Decimal
14from typing import Dict, List, Optional, Set, Tuple
13 15
14from beancount.core.data import Commodity, Entries, Transaction 16from beancount.core.data import Commodity, Entries, Transaction
15from beancount.core import data 17from beancount.core import data
@@ -22,6 +24,8 @@ __plugins__ = ('add_implicit_prices',)
22 24
23ImplicitPriceError = collections.namedtuple('ImplicitPriceError', 'source message entry') 25ImplicitPriceError = collections.namedtuple('ImplicitPriceError', 'source message entry')
24 26
27EntryId = Tuple[dt.date, data.Currency, Optional[Decimal], data.Currency]
28
25 29
26METADATA_FIELD = "__implicit_prices__" 30METADATA_FIELD = "__implicit_prices__"
27IMPLICIT_PRICES_META = "implicit-prices" 31IMPLICIT_PRICES_META = "implicit-prices"
@@ -65,9 +69,10 @@ def add_implicit_prices(entries: Entries,
65 errors.extend(fetch_errors) 69 errors.extend(fetch_errors)
66 70
67 # A dict of (date, currency, cost-currency) to price entry. 71 # A dict of (date, currency, cost-currency) to price entry.
68 new_price_entry_map = {} 72 new_price_entry_map: Dict[EntryId, data.Price] = {}
69 73
70 balances = collections.defaultdict(inventory.Inventory) 74 balances: Dict[data.Account, inventory.Inventory] = collections.defaultdict(
75 inventory.Inventory)
71 for entry in entries: 76 for entry in entries:
72 # Always replicate the existing entries. 77 # Always replicate the existing entries.
73 new_entries.append(entry) 78 new_entries.append(entry)
diff --git a/mypy.ini b/mypy.ini
index a98d7fb..1403171 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -1,9 +1,8 @@
1[mypy] 1[mypy]
2check_untyped_defs = True 2check_untyped_defs = True
3ignore_errors = False 3ignore_errors = False
4ignore_missing_imports = True
5strict_optional = True 4strict_optional = True
6warn_unused_ignores = True 5warn_unused_ignores = False
7warn_redundant_casts = True 6warn_redundant_casts = True
8warn_unused_configs = True 7warn_unused_configs = True
9 8
@@ -12,3 +11,6 @@ ignore_missing_imports = True
12 11
13[mypy-pdfminer.*] 12[mypy-pdfminer.*]
14ignore_missing_imports = True 13ignore_missing_imports = True
14
15[mypy-secretstorage.*]
16ignore_missing_imports = True