Templated reports with eguile2

Chris Dennis cgdennis at btinternet.com
Thu Feb 5 19:30:15 EST 2009


Hello GnuCash developers

A first draft of my system for using templates to create GnuCash reports 
is now ready for people to play with.

It can be bolted on to any GnuCash installation very simply.  Download 
three files from http://www.fbcs.co.uk/files/gnucash :

     eguile2.scm
     egreport1.scm
     egreport1.eguile

I gave Neale Pickett's eguile.scm a major rewrite (for reasons listed in 
the code), and I'm calling it eguile2.scm for now.  It's implemented as 
a standard Guile module.  It has been developed using Guile 1.6.8, and 
should work with 1.8 too (but I haven't tested that yet).

eguile2.scm needs to be put into the same directory as other reports --
that's /usr/share/gnucash/guile-modules/gnucash/report/ on my system.

egreport1.scm is a typical Gnucash report in the sense that it can
either be installed as a mainstream module in
/usr/share/gnucash/guile-modules/gnucash/report/, or added to the user's
custom reports by adding a line in ~/.gnucash/config.user indicating its 
location (see http://wiki.gnucash.org/wiki/Custom_Reports ).  It shows 
up as a report called "Minimal Invoice Report using eguile2".  I put 
egreport1.scm in ~/.gnucash, so I have the following line in config.user:

   (load-from-path "/home/chris/.gnucash/egreport1.scm")

egreport1.eguile is the template, which also needs to be put into 
~/.gnucash (because that location is hard-coded in egreport1.scm at the 
moment).

egreport1 is a VERY basic customer invoice, showing company and customer 
details, and invoice lines and totals.  It ignores discounts and taxes, 
and also does not show payments, and displays nonsense numbers if you 
select a bill rather than an invoice, so please don't use it for real yet.

The template is a mix of HTML and Guile code, a bit like using PHP.  For 
example

    <h1>This is Guile version <?scm:d (version) ?></h1>

There are the beginnings of some documentation in the comments near the 
top of eguile2.scm.

Comments can be included in the template in either HTML form:

    <!-- HTML comment -->

or Guile form:

    ; Guile comment

BUT be very careful that the two don't overlap, or there will be errors. 
  Error messages are displayed in a very basic form in the report window.

As with any GnuCash report, GnuCash has to be restarted if any code in 
egreport1.scm is changed.  But the good news is that if you make changes 
to the template, i.e. egreport1.eguile, you only need to reload the 
report to see the effects of the change.

Known issues:
- It's Linux only at the moment, simply because of the filename handling
in egreport1.scm.
- eguile2.scm creates a processed copy of the template in 
/tmp/gnucash.eguile2.script.scm (that name is hard-coded and is also 
Linux-specific).  The file is useful for debugging the template.

Please give it a try and let me know what you think.

cheers

Chris
-- 
Chris Dennis                                  cgdennis at btinternet.com
Fordingbridge, Hampshire, UK


More information about the gnucash-devel mailing list