Skip to content

Commit

Permalink
feat: get_available_cash now takes as input settlement_fund_balance
Browse files Browse the repository at this point in the history
different institutions seem to compute this in different ways.
overridable method now includes settlement_fund_balance for use if
needed in importers
  • Loading branch information
redstreet committed Feb 27, 2023
1 parent 74a8df0 commit 22831a1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions beancount_reds_importers/importers/fidelity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ def get_target_acct_custom(self, transaction, ticker=None):
if transaction.memo.startswith("FEES"):
return self.config['fees']
return None

def get_available_cash(self, settlement_fund_balance=0):
return getattr(self.ofx_account.statement, 'available_cash', None)
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ def get_balance_positions(self):
# TODO
raise "Not supported"

def get_available_cash(self):
def get_available_cash(self, settlement_fund_balance=0):
return None
2 changes: 1 addition & 1 deletion beancount_reds_importers/libreader/csvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def get_transactions(self):
continue
yield ot

def get_available_cash(self):
def get_available_cash(self, settlement_fund_balance=0):
return None

# TOOD: custom, overridable
Expand Down
9 changes: 7 additions & 2 deletions beancount_reds_importers/libreader/ofxreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ def get_balance_positions(self):
return []
yield from self.ofx_account.statement.positions

def get_available_cash(self):
return getattr(self.ofx_account.statement, 'available_cash', None)
def get_available_cash(self, settlement_fund_balance=0):
available_cash = getattr(self.ofx_account.statement, 'available_cash', None)
if available_cash is not None:
# Some institutions compute available_cash this way. For others, override this method
# in the importer
return available_cash - settlement_fund_balance
return None

def get_max_transaction_date(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion beancount_reds_importers/libreader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def get_balance_statement(self, file=None):
def get_balance_positions(self):
return []

def get_available_cash(self):
def get_available_cash(self, settlement_fund_balance=0):
return None
5 changes: 2 additions & 3 deletions beancount_reds_importers/libtransactionbuilder/investments.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,14 @@ def extract_balances_and_prices(self, file, counter):
new_entries.append(price_entry)

# ----------------- available cash
available_cash = self.get_available_cash()
available_cash = self.get_available_cash(settlement_fund_balance)
if available_cash is not None:
balance = available_cash - settlement_fund_balance
metadata = data.new_metadata(file.name, next(counter))
metadata.update(self.build_metadata(file, metatype='balance_cash'))
try:
bal_date = date if date else self.file_date(file).date() # unavailable file_date raises AttributeError
balance_entry = data.Balance(metadata, bal_date, self.config['cash_account'],
amount.Amount(balance, self.currency),
amount.Amount(available_cash, self.currency),
None, None)
new_entries.append(balance_entry)
except AttributeError:
Expand Down

0 comments on commit 22831a1

Please sign in to comment.