Just an FYI, if you're using the ledger python interface, balance
objects compare the opposite of the sign.

Given this input:

--
2013-01-01 Items for One
  Customer:One:Items   $100
  Accounts:Checking

2013-01-02 Items for Two
  Customer:Two:Items  $40
  Accounts:Checking
--
and this code:


--
import ledger

journal = ledger.read_journal("py_acc_re_test.lgr")
comms = ledger.commodities
usd = comms.find_or_create('$')

def balance_posts_subaccts(account, start_d=None, end_d=None):
    total = ledger.Balance()
    for post in account.posts():
        if start_d and post.date < start_d:
            continue
        if end_d and post.date > end_d:
            continue
        total += post.amount
    for subacct in account.accounts():
        total += balance_posts_subaccts(subacct, start_d, end_d)
    return total

def balance_re_subaccts(top_account, match_account, start_d=None, end_d=None):
    total = ledger.Balance()
    for subacct in top_account.accounts():
        if subacct.name == match_account:
            total += balance_posts_subaccts(subacct, start_d, end_d)
        else:
            total += balance_re_subaccts(subacct,match_account,start_d,end_d)
    return total

account = journal.find_account_re("")

bal1 = balance_re_subaccts(account,"One")
bal2 = balance_re_subaccts(account,"Two")

print "bal1 = %s" % bal1.value(usd)
print "bal2 = %s" % bal2.value(usd)

if bal1 > bal2:
    print "bal1 is more"
else:
    print "bal2 is more"
---

The output is:
--
bal1 = $100
bal2 = $40
bal2 is more
--

I'm assuming there's some reversed comparison operator in there somewhere.

Thanks,
Zack

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to