Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ledgercalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@
# find the balance for an account
def balance_acct(acct_name, start_d=None, end_d=None):
total = ledger.Balance()
splitter = " "
payee = None
if splitter in acct_name:
index = acct_name.index(splitter)
payee = acct_name[(index + 4):]
acct_name = acct_name[:index]
if re.match(r"^[A-Za-z:_\-\ ]*$",acct_name): # if the account name lacks re's
account = journal.find_account_re(acct_name)
return bal_posts_subacct(account, start_d, end_d)
return bal_posts_subacct(account, start_d, end_d, payee)
else:
return bal_re_acct(acct_name,start_d,end_d)

# recursively accumulate the balance for all posts/subaccounts of given account
def bal_posts_subacct(account, start_d=None, end_d=None):
def bal_posts_subacct(account, start_d=None, end_d=None, payee=None):
total = ledger.Balance()
if account == None: # if nothing was matched, return empty balance object
return total
Expand All @@ -48,6 +54,8 @@ def bal_posts_subacct(account, start_d=None, end_d=None):
continue
if end_d and post.date > end_d:
continue
if payee and payee != post.xact.payee:
continue
total += post.amount
for subacct in account.accounts():
total += bal_posts_subacct(subacct, start_d, end_d)
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ adds two accounts, pushes result onto stack.

Accounts containing spaces/regex must be put in double quotes.

To filter transactions by payee, append two spaces and then payee to account name, like this:

"Income:Wages Acme, Inc." account2 +

Variables are prefixed with `$`, and are assigned like this:

$taxrate 0.091 =
Expand Down