Custom .scm script: Query account balance

Eric Wheeler gnucash-devel at lists.ewheeler.net
Tue Oct 4 19:35:24 EDT 2016


On Tue, 4 Oct 2016, Derek Atkins wrote:

> Hi,
> 
> Eric Wheeler <gnucash-devel at lists.ewheeler.net> writes:
> 
> > Hello all,
> >
> > I would like to update our invoice .scm template to include a balance from 
> > an account containing the customer's name (this is separate from any 
> > accounts receivable, it is a retainer liability account).
> >
> > I tried digging through the account piechart.scm and the taxinvoice.scm to 
> > see if I can come up with a way to query the account something like this:
> >
> > gnc:account-get-comm-balance-at-date append("Liabilities::Retainers::" coyname)
> 
> First, you probably don't need the double-colons.
> 
> > But I'm not sure how to pass today's date. It's been years since I've 
> > written scheme so any help would be greatly appreciated!
> 
> (current-time) ??   Or perhaps (localtime (current-time)) -- depending
> on what you need.

I'm still trying to get to the point where I can specify an account 
(hard-coded) by name in my report to get that account's balance.

I can map all of numerical values for balanaces, but they report all 0s 
for all accounts. This makes me think that "current-time" is being 
evaluated as the epoch, perhaps because it is an invalid data type for the 
gnc:account-get-balance-at-date function.

Do you know how the gnc:account-get-balance-at-date function expects date 
to be represented?

(display (append
    (map
        (lambda (x) (gnc:gnc-numeric-num (gnc:account-get-balance-at-date x (current-time) 0)))
        (gnc-account-get-descendants-sorted (gnc-get-current-root-account))
    ))
)


--
Eric Wheeler
> 
> > -Eric
> >
> > --
> > Eric Wheeler
> > _______________________________________________
> > gnucash-devel mailing list
> > gnucash-devel at gnucash.org
> > https://lists.gnucash.org/mailman/listinfo/gnucash-devel
> 
> -derek
> 
> -- 
>        Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
>        Member, MIT Student Information Processing Board  (SIPB)
>        URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
>        warlord at MIT.EDU                        PGP key available
> 


More information about the gnucash-devel mailing list