diff --git a/ledgercalc.py b/ledgercalc.py index 54fbb4d..b361314 100644 --- a/ledgercalc.py +++ b/ledgercalc.py @@ -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 @@ -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) diff --git a/readme.md b/readme.md index f6baf22..cf3215f 100644 --- a/readme.md +++ b/readme.md @@ -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 =