Difference between revisions of "Custom Reports"
(Remove drScheme related noise) |
Rob Russell (talk | contribs) (Added path for Suse and link to Guile docs) |
||
Line 5: | Line 5: | ||
=== Example Reports === | === Example Reports === | ||
− | A good place to start is to examine the source code of the reports included with GnuCash. | + | A good place to start is to examine the source code of the reports included with GnuCash. The location varies a little with different operating systems: |
+ | * On Gentoo look in <tt>/usr/share/gnucash/guile-modules/gnucash/report</tt> | ||
+ | * On BSD look in <tt>/usr/local/share/gnucash/guile-modules/gnucash/report</tt> | ||
+ | * On OpenSuse look in <tt>/opt/gnome/share/gnucash/guile-modules/gnucash/report</tt> | ||
− | |||
<tt>hello-world.scm</tt> is specially written to demonstrate the basic structure of a report. | <tt>hello-world.scm</tt> is specially written to demonstrate the basic structure of a report. | ||
Line 68: | Line 70: | ||
* [http://www.htdp.org/ How to Design Programs] | * [http://www.htdp.org/ How to Design Programs] | ||
* Mastering Scheme is highly eased after reading [http://www.scheme.com/tspl2d/ The Scheme Progamming Language] by R. Kent Dybvig | * Mastering Scheme is highly eased after reading [http://www.scheme.com/tspl2d/ The Scheme Progamming Language] by R. Kent Dybvig | ||
+ | * [http://www.gnu.org/software/guile/docs/docs.html Guile documentation] |
Revision as of 01:03, 22 March 2007
Contents
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.
Example Reports
A good place to start is to examine the source code of the reports included with GnuCash. The location varies a little with different operating systems:
- On Gentoo look in /usr/share/gnucash/guile-modules/gnucash/report
- On BSD look in /usr/local/share/gnucash/guile-modules/gnucash/report
- On OpenSuse look in /opt/gnome/share/gnucash/guile-modules/gnucash/report
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 shown 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
Programming tools
Any reasonable source/text editor, including emacs and vi, should provide basic syntax support for source-code editing. One of the most basic and important for editings scheme/lisp sources is parenthesis matching. Other scheme environments (such as drScheme) might also be useful for editing the sources, but note that they might allow constructs that are not valid in guile.
Loading the Report
There are two ways to load a report at startup of GnuCash: from a user account, or from the installation tree. You will likely want to use the user account approach.
From a user account
In your home directory, edit ~/.gnucash/config.user to add a line of the form:
(load-from-path "/path/to/my/personal/report.scm")
You will also have to comment out the line in the code for your report that defines the module:
;(define-module (gnucash report my-report-module))
Then restart GnuCash.
See gnucash-user email from Derek Atkins.
From the installed report directory
Alternatively, you can copy the report to the installed report directory. Make sure you have included a module definition as shown above. 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 will 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")
gnc:debug only displays when some environment variable is set. I don't know where and how so I use gnc:warn instead.
Other Resources
Old GnuCash Report Information
(may be very out of date)
- Version 1.6 report documentation
- FAQ#Q:_I.27d_like_to_write_my_own_custom_reports._Where_should_I_start.3F
- From the mailing list
Learning Scheme
- Teach Yourself Scheme in Fixnum Days
- Structure and Interpretation of Computer Programs
- How to Design Programs
- Mastering Scheme is highly eased after reading The Scheme Progamming Language by R. Kent Dybvig
- Guile documentation