Skip to content

Commit

Permalink
refactor: eliminate include_balances
Browse files Browse the repository at this point in the history
Instead, implement methods that return nothing, but can be overridden
where there is something to return
  • Loading branch information
redstreet committed Jan 1, 2023
1 parent 71a0114 commit 5ed7d21
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
1 change: 0 additions & 1 deletion beancount_reds_importers/libreader/csvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def initialize_reader(self, file):
# TODO: move out elsewhere?
# self.currency = self.ofx_account.statement.currency.upper()
self.currency = self.config.get('currency', 'USD')
self.includes_balances = False
self.date_format = '%m/%d/%Y' # TODO: move into class variable, into reader.Reader
self.file_read_done = False
# else:
Expand Down
11 changes: 6 additions & 5 deletions beancount_reds_importers/libreader/ofxreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def initialize_reader(self, file):
self.reader_ready = True
if self.reader_ready:
self.currency = self.ofx_account.statement.currency.upper()
self.includes_balances = hasattr(self.ofx_account.statement, 'balance')

def match_account_number(self, file_account, config_account):
"""We many not want to store entire credit card numbers in our config. Or a given ofx may not contain
Expand All @@ -45,19 +44,21 @@ def read_file(self, file):
pass

def get_transactions(self):
for ot in self.ofx_account.statement.transactions:
yield ot
yield from self.ofx_account.statement.transactions

def get_balance_statement(self):
if not hasattr(self.ofx_account.statement, 'balance'):
return []
date = self.get_max_transaction_date()
if date:
date += datetime.timedelta(days=1) # See comment in get_max_transaction_date() for explanation
Balance = namedtuple('Balance', ['date', 'amount'])
yield Balance(date, self.ofx_account.statement.balance)

def get_balance_positions(self):
for pos in self.ofx_account.statement.positions:
yield pos
if not hasattr(self.ofx_account.statement, 'positions'):
return []
yield from self.ofx_account.statement.positions

def get_available_cash(self):
return getattr(self.ofx_account.statement, 'available_cash', None)
Expand Down
9 changes: 9 additions & 0 deletions beancount_reds_importers/libreader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ def file_name(self, file):

def file_account(self, _):
return self.config['main_account'].replace(':{ticker}', '').replace(':{currency}', '')

def get_balance_statement(self):
return []

def get_balance_positions(self):
return []

def get_available_cash(self):
return None
1 change: 0 additions & 1 deletion beancount_reds_importers/libreader/xlsxreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def initialize_reader(self, file):
self.reader_ready = True

self.currency = self.config.get('currency', 'USD')
self.includes_balances = False

def read_raw(self, file):
rdr = etl.fromxlsx(file.name, read_only=True)
Expand Down
4 changes: 1 addition & 3 deletions beancount_reds_importers/libtransactionbuilder/banking.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def extract(self, file, existing_entries=None):

new_entries.append(entry)

if self.includes_balances:
new_entries += self.extract_balance(file, counter)

new_entries += self.extract_balance(file, counter)
new_entries += self.extract_custom_entries(file, counter)

return new_entries
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(self, config):
self.initialized = False
self.reader_ready = False
self.custom_init_run = False
self.includes_balances = False
self.price_cost_both_zero_handler = None

# For overriding in custom_init()
Expand Down Expand Up @@ -392,8 +391,7 @@ def extract(self, file, existing_entries=None):
new_entries = []

new_entries += self.extract_transactions(file, counter)
if self.includes_balances:
new_entries += self.extract_balances_and_prices(file, counter)
new_entries += self.extract_balances_and_prices(file, counter)

new_entries += self.extract_custom_entries(file, counter)

Expand Down
1 change: 0 additions & 1 deletion beancount_reds_importers/schwab_checking_csv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def custom_init(self):
self.skip_head_rows = 1
self.skip_tail_rows = 0
self.skip_comments = '# '
self.includes_balances = True
self.header_map = {
"Date": "date",
"Type": "type",
Expand Down
4 changes: 1 addition & 3 deletions beancount_reds_importers/schwab_csv_balances/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Importer(investments.Importer, csv_multitable_reader.Importer):
IMPORTER_NAME = 'Schwab Brokerage Balances CSV'

def custom_init(self):
self.includes_balances = True
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*_Transactions_'
self.header_identifier = 'Transactions for account'
Expand Down Expand Up @@ -68,5 +67,4 @@ def prepare_tables(self):

def get_balance_positions(self):
for section in self.config['section_headers']:
for ot in self.alltables[section].namedtuples():
yield ot
yield from self.alltables[section].namedtuples()
1 change: 0 additions & 1 deletion beancount_reds_importers/workday/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def custom_init(self):
self.max_rounding_error = 0.04
self.filename_pattern_def = '.*_Complete'
self.header_identifier = '- Complete' + self.config.get('custom_header', '')
self.includes_balances = False
self.date_format = '%m/%d/%Y'
self.skip_head_rows = 1
# TODO: need to be smarter about this, and skip only when needed
Expand Down

0 comments on commit 5ed7d21

Please sign in to comment.