diff options
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 | ||
237 | def extract_cards(card_accounts: Dict[str, str]) -> Extractor: | 237 | def 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 | ||
7 | from importers.transferwise.client import main | 7 | from beancount_extras_kris7t.importers.transferwise.client import main |
8 | 8 | ||
9 | 9 | ||
10 | if __name__ == '__main__': | 10 | if __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: | |||
25 | def _import_config(config_path: str) -> Importer: | 25 | def _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 | |||
65 | def _get_date_range(from_date: Optional[dt.date], | 65 | def _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¤cy=' | 144 | f'?intervalStart={from_time_str}&intervalEnd={to_time_str}&type=COMPACT¤cy=' |
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 | ||
11 | import collections | 11 | import collections |
12 | from typing import List, Tuple, Set | 12 | import datetime as dt |
13 | from decimal import Decimal | ||
14 | from typing import Dict, List, Optional, Set, Tuple | ||
13 | 15 | ||
14 | from beancount.core.data import Commodity, Entries, Transaction | 16 | from beancount.core.data import Commodity, Entries, Transaction |
15 | from beancount.core import data | 17 | from beancount.core import data |
@@ -22,6 +24,8 @@ __plugins__ = ('add_implicit_prices',) | |||
22 | 24 | ||
23 | ImplicitPriceError = collections.namedtuple('ImplicitPriceError', 'source message entry') | 25 | ImplicitPriceError = collections.namedtuple('ImplicitPriceError', 'source message entry') |
24 | 26 | ||
27 | EntryId = Tuple[dt.date, data.Currency, Optional[Decimal], data.Currency] | ||
28 | |||
25 | 29 | ||
26 | METADATA_FIELD = "__implicit_prices__" | 30 | METADATA_FIELD = "__implicit_prices__" |
27 | IMPLICIT_PRICES_META = "implicit-prices" | 31 | IMPLICIT_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) |
@@ -1,9 +1,8 @@ | |||
1 | [mypy] | 1 | [mypy] |
2 | check_untyped_defs = True | 2 | check_untyped_defs = True |
3 | ignore_errors = False | 3 | ignore_errors = False |
4 | ignore_missing_imports = True | ||
5 | strict_optional = True | 4 | strict_optional = True |
6 | warn_unused_ignores = True | 5 | warn_unused_ignores = False |
7 | warn_redundant_casts = True | 6 | warn_redundant_casts = True |
8 | warn_unused_configs = True | 7 | warn_unused_configs = True |
9 | 8 | ||
@@ -12,3 +11,6 @@ ignore_missing_imports = True | |||
12 | 11 | ||
13 | [mypy-pdfminer.*] | 12 | [mypy-pdfminer.*] |
14 | ignore_missing_imports = True | 13 | ignore_missing_imports = True |
14 | |||
15 | [mypy-secretstorage.*] | ||
16 | ignore_missing_imports = True | ||