def semi_table(acc, tid, remove_empty=True, conversions=None, aname='total'): """ Given an account, create a table for the transactions contained therein (including its subaccounts).""" table = TABLE(id=tid, CLASS='semi accounts treetable') table.add(THEAD(TR(TH("Account"), TH("Amount")))) it = iter(itertree(acc)) sum_ = Wallet() for acc, td1, tr, skip in treetable_builder(table, it): if remove_empty and len(acc) == 0: skip() continue td1.add( A(acc.name, href=umap('@@AccountLedger', webaccname(acc.fullname)), CLASS='accomp')) balance = acc.balances[aname] if conversions: balance = balance.convert(conversions) sum_ += balance tr.add( TD(hwallet_paren(balance.round()) if balance else '') ) table.add(TR(TD(B("Totals")), TD(hwallet_paren(sum_)) )) return table, sum_
def render_txn_field(ledger, aname, conversions=None): """ Render two sets of postings equivalent to the accounts tree using a particular field: one that has the same effect, and one that undoes it. This function returns two lists of lines for the transactions. """ list_do = [] list_undo = [] it = iter(itertree(ledger.get_root_account())) sum_ = Wallet() for ordering, isterminal, acc in it: if len(acc) == 0: continue lbal = acc.balances.get(aname, None) if lbal.isempty(): continue if lbal is not None: lbal = lbal.convert(conversions).round() for comm, amount in lbal.iteritems(): list_do.append(' %-60s %s %s' % (acc.fullname, amount, comm)) list_undo.append(' %-60s %s %s' % (acc.fullname, -amount, comm)) return list_do, list_undo
def render_trial_field(ledger, aname, conversions=None): """ Render a trial balance of the accounts tree using a particular field. """ table = TABLE(id='balance', CLASS='accounts treetable') table.add(THEAD(TR(TH("Account"), TH("Amount"), TH(), TH("Cum. Sum")))) it = iter(itertree(ledger.get_root_account())) sum_ = Wallet() for acc, td1, tr, skip in treetable_builder(table, it): if len(acc) == 0: skip() continue td1.add( A(acc.name, href=umap('@@AccountLedger', webaccname(acc.fullname)), CLASS='accomp')) lbal = acc.balances.get(aname, None) bal = acc.balances_cumul.get(aname, None) if lbal.isempty() and bal.isempty(): skip() continue if lbal is not None: lbal = lbal.convert(conversions).round() sum_ += lbal tr.add( TD(hwallet_paren(lbal), CLASS='wallet'), ) else: tr.add( TD(CLASS='wallet'), ) if bal is not None: bal = bal.convert(conversions).round() if not lbal and bal: tr.add( TD('...'), TD(hwallet_paren(bal), CLASS='wallet'), ) ## No need to display the sum at the bottom, it's already at the top node. ## table.add(TR(TD(), TD(hwallet_paren(sum_)), TD(), TD())) return table
def page__activity(app, ctx): "Output the updated time ranges of each account." page = Template(ctx) today = date.today() table = TABLE(id='activity', CLASS='accounts treetable') table.add(THEAD(TR(TH("Account"), TH("Oldest Chk"), TH("Newest Chk"), TH("Last Posting"), TH("Days since"), ))) it = iter(itertree(ctx.ledger.get_root_account(), pred=attrgetter('checked'))) for acc, td1, tr, skip in treetable_builder(table, it): if len(acc) == 0: skip() continue td1.add( A(acc.name, href=umap('@@AccountLedger', webaccname(acc.fullname)), CLASS='accomp')) append = False row = [TD() for _ in xrange(4)] elapsed_check, elapsed_post = None, None if acc.checked: row[0].add(str(acc.check_min)) row[1].add(str(acc.check_max)) elapsed_check = (today - acc.check_max).days append = True if acc.postings: post_last = acc.postings[-1] row[2].add(str(post_last.actual_date)) elapsed_post = (today - post_last.actual_date).days append = True if append: row[3].add('%s days' % min(filter(lambda x: x is not None, [elapsed_check, elapsed_post]))) tr.extend(row) page.add(H1('Activity'), table) return page.render(app)
def page__chartofaccounts(app, ctx): page = Template(ctx) table = TABLE(id='chart-of-accounts', CLASS='accounts treetable') table.add(THEAD(TR(TH("Account"), TH("Dr/Cr"), TH("Valid Commodities")))) it = iter(itertree(ctx.ledger.get_root_account())) for acc, td1, tr, skip in treetable_builder(table, it): if len(acc) == 0: skip() continue td1.add( A(acc.name, href=umap('@@AccountLedger', webaccname(acc.fullname)), CLASS='accomp')) tr.add( TD(acc.getatype()), TD(", ".join(acc.commodities) if acc.commodities else ""), ## TD("%d" % len(acc.postings)), ) page.add(H1("Chart of Accounts"), table) return page.render(app)