From 45fb8554a08742e758b89e2f542753513dd1c698 Mon Sep 17 00:00:00 2001 From: Red S Date: Wed, 3 Apr 2024 18:55:07 -0700 Subject: [PATCH] fix: one-file-per-account broke with smart_importer #97 --- .../importers/workday/__init__.py | 3 --- .../libtransactionbuilder/banking.py | 6 ------ .../libtransactionbuilder/investments.py | 12 +++--------- .../libtransactionbuilder/paycheck.py | 6 ------ .../libtransactionbuilder/transactionbuilder.py | 11 +++++++++++ 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/beancount_reds_importers/importers/workday/__init__.py b/beancount_reds_importers/importers/workday/__init__.py index ff06c3f..e8c4261 100644 --- a/beancount_reds_importers/importers/workday/__init__.py +++ b/beancount_reds_importers/importers/workday/__init__.py @@ -50,6 +50,3 @@ def valid_header_label(label): for header in table.header(): table = table.rename(header, valid_header_label(header)) self.alltables[section] = table - - def build_metadata(self, file, metatype=None, data={}): - return {"filing_account": self.config["main_account"]} diff --git a/beancount_reds_importers/libtransactionbuilder/banking.py b/beancount_reds_importers/libtransactionbuilder/banking.py index abddbca..b4816b9 100644 --- a/beancount_reds_importers/libtransactionbuilder/banking.py +++ b/beancount_reds_importers/libtransactionbuilder/banking.py @@ -43,12 +43,6 @@ def build_account_map(self): # } pass - def build_metadata(self, file, metatype=None, data={}): - """This method is for importers to override. The overridden method can - look at the metatype ('transaction', 'balance', 'account', 'commodity', etc.) - and the data dictionary to return additional metadata""" - return {} - def match_account_number(self, file_account, config_account): return file_account.endswith(config_account) diff --git a/beancount_reds_importers/libtransactionbuilder/investments.py b/beancount_reds_importers/libtransactionbuilder/investments.py index 7dca20d..81b3466 100644 --- a/beancount_reds_importers/libtransactionbuilder/investments.py +++ b/beancount_reds_importers/libtransactionbuilder/investments.py @@ -141,12 +141,6 @@ def build_account_map(self): ) # fmt: on - def build_metadata(self, file, metatype=None, data={}): - """This method is for importers to override. The overridden method can - look at the metatype ('transaction', 'balance', 'account', 'commodity', etc.) - and the data dictionary to return additional metadata""" - return {} - def custom_init(self): if not self.custom_init_run: self.max_rounding_error = 0.04 @@ -276,9 +270,9 @@ def generate_trade_entry(self, ot, file, counter): if "sell" in ot.type: units = -1 * abs(ot.units) if not is_money_market: - metadata["todo"] = ( - "TODO: this entry is incomplete until lots are selected (bean-doctor context )" # noqa: E501 - ) + metadata[ + "todo" + ] = "TODO: this entry is incomplete until lots are selected (bean-doctor context )" # noqa: E501 if ot.type in [ "reinvest" ]: # dividends are booked to commodity_leaf. Eg: Income:Dividends:HOOLI diff --git a/beancount_reds_importers/libtransactionbuilder/paycheck.py b/beancount_reds_importers/libtransactionbuilder/paycheck.py index b487b07..a7f26ea 100644 --- a/beancount_reds_importers/libtransactionbuilder/paycheck.py +++ b/beancount_reds_importers/libtransactionbuilder/paycheck.py @@ -131,12 +131,6 @@ def build_postings(self, entry): newentry = entry._replace(postings=postings) return newentry - def build_metadata(self, file, metatype=None, data={}): - """This method is for importers to override. The overridden method can - look at the metatype ('transaction', 'balance', 'account', 'commodity', etc.) - and the data dictionary to return additional metadata""" - return {} - def extract(self, file, existing_entries=None): self.initialize(file) config = self.config diff --git a/beancount_reds_importers/libtransactionbuilder/transactionbuilder.py b/beancount_reds_importers/libtransactionbuilder/transactionbuilder.py index f789e9b..07694eb 100644 --- a/beancount_reds_importers/libtransactionbuilder/transactionbuilder.py +++ b/beancount_reds_importers/libtransactionbuilder/transactionbuilder.py @@ -44,3 +44,14 @@ def set_config_variables(self, substs): self.config["filing_account"] = self.remove_empty_subaccounts( filing_account ) + + def build_metadata(self, file, metatype=None, data={}): + """This method is for importers to override. The overridden method can + look at the metatype ('transaction', 'balance', 'account', 'commodity', etc.) + and the data dictionary to return additional metadata""" + + # This 'filing_account' is read by a patch to bean-extract so it can output transactions to + # a file that corresponds with filing_account, when the one-file-per-account feature is + # used. + acct = self.config.get("filing_account", self.config.get("main_account", None)) + return {"filing_account": acct}