Python Bindings

Marc Shapiro marcnshap at
Sun Jun 1 18:07:38 EDT 2014

On 05/31/2014 03:43 PM, John Ralls wrote:
> On May 31, 2014, at 3:14 PM, Marc Shapiro <marcnshap at> wrote:
>> Ooops!  I meant to send this to the list.
>> Marc
>> -----------------
>> All in all it sounds like it would be a lot more work that I am really up to at this time.  Of course, learning Scheme/Guile is not really any better.
>> What I want is to be able to generate a Balance Sheet with all current transactions, then add in any budget items and/or future transactions up to an arbitrary date in the future to project all of the Balance Sheet accounts as of that arbitrary future date.
>> It seems like it shouldn't be difficult to merge the Budget and Future Transaction info from their reports into the Balance Sheet if I already knew Guile.  Unfortunately, I don't know Guile.  LISP and its derivatives are just way too different from, say, C/C++ or Python for me to easily get the hang of it.
> Well, you could always write what you need in C or C++ and call it from Python with ctypes or a custom wrapper.
> Regards,
> John Ralls
I think that I have found a simpler solution, but it is not quite 
working.  I have narrowed down where the problem is and I think that 
this would be very trivial if I understood guile and the gnucash 
reporting system better, but I don't.  If anyone could look at what I 
have and suggest a fix I would appreciate it.

I am now looking at only the differences between account-summary.scm and 
sx-summary.scm.  These two reports are virtually identical.  The format 
is the same for both of them.  The only differences are the title 
displayed at the top of the report and the values displayed for each 

The Account Summary (account-summary.scm) has a single report date in 
the title and the values for each account are the sum of the actual 
transactions through that date.  The Scheduled Transaction summary 
(sx-summary.scm) has a date range in the title and the values for each 
account are the sum of the future transactions within that date range.

The following code is a combination of code from both reports.  This 
section begins at line 331 in sx-summary.scm and at line 341 in 
account-summary.scm.  The differences are as follows:

The line "(sx-value-hash (gnc-sx-all-instantiate-cashflow-all 
from-date-tp to-date-tp))" as well as the entire function 
"get-balance-fn" are only in sx-summary.scm.

The function "get-total-balance-fn" is only in account-summary.scm and 
uses date-tp instead of from-date-tp.

Other than the above differences the code in this section is identical.

        (let* (
                (sx-value-hash (gnc-sx-all-instantiate-cashflow-all 
from-date-tp to-date-tp))
                (chart-table #f)                    ;; gnc:html-acct-table
                (hold-table (gnc:make-html-table))  ;; temporary 
                (build-table (gnc:make-html-table)) ;; gnc:html-table 
                 (lambda (account)
                    account from-date-tp #f)))
                (table-env                      ;; parameters for :make-
                  (list 'start-date from-date-tp)
                  (list 'end-date to-date-tp)
                  (list 'display-tree-depth tree-depth)
                  (list 'depth-limit-behavior bottom-behavior)
                  (list 'report-commodity report-commodity)
                  (list 'exchange-fn exchange-fn)
                  (list 'parent-account-subtotal-mode parent-total-mode)
                  (list 'zero-balance-mode (if show-zb-accts?
                  (list 'account-label-mode (if use-links?
                  (list 'get-balance-fn
                   (lambda (account start-date end-date)
                     (let* ((balance-collector 
                            (guid (gncAccountGetGUID account))
                            (num-bal (hash-ref sx-value-hash guid)))
                       (if num-bal
                           (if (eq? 0 (gnc:gnc-numeric-denom num-bal))
                               (gnc:warn "Oops, invalid gnc_numeric when 
looking up SX balance for account GUID " guid ": " num-bal)
                                  (xaccAccountGetCommodity account)
                                 ;;(gnc:warn "Yay, we found SX balance 
for account GUID " guid)
                           ;;(gnc:warn "No SX balance for account GUID " 

If I run the code as above, I get only the value of the scheduled 
transactions (identical to sx-summary.scm, even though the function 
"get-toal-balance-fn" from account-summary.scm is included).  If I 
comment out the lines that are unique to sx-summary.scm then I get 
values equal to those given by account-summary.scm (as would be 
expected).  If I comment out only the line "(sx-value-hash 
(gnc-sx-all-instantiate-cashflow-all from-date-tp to-date-tp))" then I 
get a report error.  If I comment out only the function "get-balance-fn" 
then I get all zeros for the account balances.

My question is:  How can I modify this code so that the balance that I 
get for each account is the sum of what I would get from each of the 
individual reports?  Since I can modify this code, simply by commenting 
out certain lines, to give me either set of values then it seems that I 
ought to be able to get it to give me the set of the sums of both 
values.  Unfortunately, I am not familiar enough with either guile, or 
the gnucash reporting system to figure this one out.  Can anyone help me 
with this?


More information about the gnucash-devel mailing list