Custom Reports in GnuCash
Unfortunately, at the present time writing a custom report for GnuCash requires a little bit of hacking. This wiki page should contain some information to help you get started, since there is no official documentation.
Note: I am using GnuCash 2.0.1 as I write this.
A good place to start is to examine the source code of the reports included with GnuCash. On my Gentoo system, they are located in
hello-world.scm is specially written to demonstrate the basic structure of a report.
The GnuCash API
The GnuCash application programming interface is quite intimidating. Luckily, for the reports, most of the stuff needed can be found in the scheme sources. Here some random examples of handy procedures (paths used are based on a mac OS X 10.3.9 Fink installation):
- create a monetary object: gnc:make-gnc-monetary /sw/share/gnucash/scm/gnc-numeric.scm
- get the amount of a monetary object: gnc:gnc-monetary-amount /sw/share/gnucash/scm/gnc-numeric.scm
- get an account name: gnc:account-get-name /sw/share/gnucash/guile-modules/g-wrapped/gw-engine-spec.scm
First of all I think Scheme is a powerful and wonderful programming language. That said, without a proper editor the parenthesis balancing will drive you mad. Without the help of drScheme I would not touch any reasonable sized Scheme sourcecode. The killer function drScheme offers is the highlighting of the enclosed lines of code when clicking a start or end parenthesis. So you can quickly find out whether the hierarchy is as planned. Check out drScheme here: drScheme it is released under the GNU Library General Public License (LGPL).
Testing a Report
Copy the report to the report directory. Then edit the appropriate Scheme file to register your report with the reporting system. You will have to register the report in one of the following places, depending on which submenu you want it to appear.
- Standard Reports: standard-reports.scm
- Business Reports: business-reports.scm
- Utility Reports: utility-reports.scm
Then, restart GnuCash. You need to restart GnuCash every time you change a report.
If, like me, you run GC from within X11, you best start GC from a X11 terminal window. For debugging you might add log messages with gnc:warn, e.g. (gnc:warn "here I am") As gnc:debug only displays when some environment variable is set. I don't know where and how so I use gnc:warn instead.
Old GnuCash Report Information
(may be very out of date)
- Version 1.6 report documentation
- From the mailing list