We create and adapt free software

Accounting reports with Jasper

Just a quick note for those interested in trying a new set of accounting reports. We've published account_jasper_report module for OpenERP v6, which provides Journal, Trial Balance, General Ledger, and Invoice List reports. Until now, we've been using account_financial_report which had some modifications over standard and older reports, but unfortunately performance was very poor for companies with lots of account moves.

The new module is very fast and can create a General Ledger report with 58.000 move lines and 1.300 pages in just 1 minute and 30 seconds. (We had to wait several hours with older reports!).

Note that you will need latest version of jasper_reports module (download here).

Access database structure from iReport

We have recently added a new feature to jasper_reports module that allows users to have access to fields structure from iReport, avoiding the need of creating the XML file. Note that although the module works with both v5 and v6 this feature will only be available in v6.

Using this functionality is really easy. Simply install latest version of jasper_reports module and in iReport create a new Remote XML file datasource. And in XML URL specify OpenERP's XML-RPC URL and append "/jasper/" and the internal name of the model we want to use (in the example "purchase.order"). After that we can add several paramaters, but all of them are optional, because they can be specified in openerp's server configuration file and they also have default values.  Here's a list of parameters available:

Payables and receivables forecast

 We just released a new module called 'nan_account_forecast' which basically adds a new report (based on Jasper Reports) to group account move lines by expirty date. It is specially useful for payments and receivable forecasts based on the information in account move lines.

Users can select the desired payments by their own filters to eventually select all resulting records and print the report. The module can be found in extra-addons (v5) branch in bazaar or simply download it as a zip file.

You can see in this sample report, it is pretty simple but it is a must in almost all installs!

Generating Jasper Reports from several models

When you need to create a new report using the jasper_reports module, you must use as base model, the one in the screen you want the button to be displayed.
 
For example, say you want to create a report that displays all product information, including its picture in a nicely designed brochure. In this case, the model will be 'product.product' and the report button will be displayed in that model, so when you go and see the list of products you'll have the possibility of selecting one or several products and print their brochure. That's usually what you need so that's not usually a problem.
 
The thing is, what if you want a button in a quotation to print the brochures of all the products in the current quotation? Until the moment, there were three possibilities: create a new report which has sale.order as base model, create a wizard or create a relate button that opens a new tab with all the products in the quotation and then select all of them and print their brochures.
 
As you can guess we've implemented a new way of solving the problem using Jasper Reports. You simply need to create a new report which will have 'sale.order' as base model, you insert a subreport element that embeds the brochure report, and add the new OPENERP_PATH_PREFIX property that will let you specify the path from the current model (that is 'sale.order') to the subreport model (that is 'product.product'). In our example, prefix path will be 'order_line/product_id'.
 
Hope next screenshot clarifies where you should add the property using iReport:
 
 

jasper_reports for Windows

Just a quick note to let Windows users to know that latest jasper_reports module in bazaar runs on Windows without troubles. You'll simply need to install java and that's it.

 
The module will be released among Koo 5.0.3, but current version in bazaar is already considered stable.

Repeating records

It's quite usual the need of repeating a page several times. For example, you may need to print 4 labels for a given delivery, one per packet. Until now, the only way of creating those four labels using Jasper Reports in OpenERP was by coding it.
 
Today, the jasper_reports module supports a new property in the report called OPENERP_COPIES_FIELD. If set, the module will repeat each record by the number of times indicated by the field in that property. So if the number of packets was stored in a field called packets you should just set OPENERP_COPIES_FIELD to packets and that's it.

Translations and user information in Jasper Reports

We've recently improved a couple of things in the jasper_reports module for OpenERP which you'll find in bazaar.
 

User field


One of them is the addition of a virtual relation field called User. This new field gives the report designer access to all the information related to the user who is executing the report, which is specially interesting in those documents that don't have a direct or indirect relation with the company, such as sale/purchase orders or pickings.
 


The recently added User field, at the end of the field list for the stock.picking model.

 
 
i18n under iReport


Another improvement has been in the translations area. In order to ease report design, we've modified the Java code so it is possible to use our i18ngroovy language within iReport. Here are the steps you need to follow in order to configure iReport (libraries can be found in jasper_reports/java/lib):



Adding the gettext library



If you work under Linux go to menú option Tools -> Libraries, click on New Library... button. Set Library Name to "i18n" and add new JAR: "gettext-commons-0.9.6.jar"


Configuring gettext library under Linux.



Adding the i18n library



Go to menú option Tools -> Options -> Classpath. If you work under Linux add new JAR "i18n.jar". If you work under Windows you should also add the "gettext-commons-0.9.6.jar" file we added in the previous step under windows.


Configuring i18n library under Linux.



Adding the i18ngroovy property



Go to menú option Tools -> Options -> Jasper Properties and add a new property: called net.sf.jasperreports.compiler.i18ngroovy with value com.nantic.jasperreports.I18nGroovyCompiler.


Configuring i18ngroovy property.


Note that windows users will be annoyed by the fact that this property is not remembered by the application when you restart it (at least with version 3.5.3) and thus has to be reset each time you open iReport. We hope iReport guys fix this issue in upcoming versions.



Setting report's Language



Once everything is configured you can use the new i18ngroovy language in your reports.


Setting report's language to i18ngroovy.


Usage



Now you can freely use the tr() set of functions to translate your reports and preview them within iReport. For example, in the following report we have the L variable defined as $F{Idioma-lang} != null && $F{Idioma-lang}.length() == 5 ? new Locale( $F{Idioma-lang}.substring(0,2), $F{Idioma-lang}.substring(3,5) ) : ( $F{Idioma-lang} != null && $F{Idioma-lang}.length() == 2 ? new Locale( $F{Idioma-lang}.substring(0,2) ) : $P{REPORT_LOCALE} ).

 
Using tr() functions under iReport.
 
 
 
Report preview under iReport.
 
 
Note that reports that use Groovy instead of i18ngroovy will still work when run under OpenERP. This is only necessary for previewing reports that use NaN's translation system.

Speeding up iReport integration

Recently jasper_reports integration module received another improvement. We added a specific menu entry in "Administration" -> "Customization" -> "Jasper Reports" -> "Jasper Reports" and it looks like this:





The screen is much more user friendly that the Low Level -> "XML Report" and allows selecting the model as well as directly uploading the reports. It has also been enhanced with respect to recent versions in that it's no longer necessary to press the "Update from attachments" button and users can upload multiple subreports.



With recent changes we feel the next steps we should carry on to improve integration is adding a new Fields Provider class to iReport and allow connecting to OpenObject directly. This would allow:


  • An entry called "openobject" in iReport which makes it easier for users to remember (instead of telling them to use "XPath")
  • Compiling and previewing reports with translations (Using our tr() family of functions)
  • Previewing reports with real data
  • Viewing Field names in user's language (as currently) but without the real field name concatenated
  • Browsing to a depth higher than five levels, which is currently almost impossible.
  • Avoid the need of creating an XML file with OpenObject client before designing (or redesigning) a report


The only implemented feature of all this is the first one:





This, however, is not very interesting as it simply shows the XML fields provider. So it just avoids making it a bit odd for the user having to select XPath.



The rest of the features are not very hard to implement but require some hours of work we can't currently affort to finance alone. However, if you think you can contribute with code or money we can make it happen faster and they're advantatges that will save quite some time of work to all of us once implemented.



So if you're interested you can contact us at "info at nan dash tic dot com" or contact with me directly at "albert at nan dash tic dot com".

Jasper (Sub)Reports and output formats

Our jasper_reports module for OpenObject recently got a three of new interesting features.



The first of them eases the creation of reports to non-english speakers by translating all fields to user's language when exporting the data template. Here you can see a screenshot of partner's fields translated into Catalan. Note that the database name field is shown right after the field string.





The second one is support for XML data in subreports. It was already possible to use subreports for headers, for example, or they could access the database but providing XML data to subreports was not possible. That meant that creating an invoice report like the one provided by default was not possible without direct database access due to the need to iterate through invoice lines first and invoice taxes later in the same form. Now it's possible to create such a report using subreports and with no need of database access. One can design the tax subreport and then integrate it with the main invoice report.



Here is a screenshot of the demo partner.jrxml, which got a new subreport called subpartner.jrxml, that shows partner events. This results in the final report iterating over all partner attachments and all events! No need to program anything, and no need to join tables from the database.









The third feature I want to talk about is the possibility to configure the output format of the report. Previously, only PDF output was possible but with recent versions you can configure the document to be rendered in RTF, ODT, ODS, XLS, HTML, PDF, CSV or TXT formats. Here there are some screenshots of the sample Jasper Partners report in several formats:






TXT output



 
XLS output




HTML output

 


PDF output




ODT output

jasper_reports NG

Right after the release of the first release candidate of Koo, we've commited a bunch of exciting changes in the jasper_reports module. Those changes can be classified in two separate areas: performance and localization.



Performance



In the performance area, we've created a java process (which is started automatically when the first report is executed) that allows avoiding the overhead of starting up the Java Virtual Machine each time a report has to be printed. The other performance improvement affects only those reports using the XML interface, which can benefit from up to 10% speedup thanks to the use of CSV files instead of XML. It is totally compatible and doesn't change anything when the user creates new reports.



Localization



If performance improvements are good news, the localization part of this post is my favorite one. Now it's possible to use translatable fields such as product name, country name, etc. In any language you want.



By default, the XML interface will create translatable fields in the same language of the user that is executing the report, but if when the field is added in iReport, you set it to type 'java.lang.Object' instead of 'java.lang.String' you can use the following syntax in the report:



$F{product_name}.get( "ca_ES" )



Even more, if the report is an invoice, for example, it will have a relation to the partner. In this case you can use:



$F{product_name}.get( $F{partner_language} )



If the translation is not available for that language, the default one will be used.



But we didn't stop localization improvements here and decided to enhance JasperReports localization features.



Put simply, jasper reports translation mechanism sucks. You're supposed to use a java bundle (.properties file) per language and use $R{key} in the expressions everywhere and obviously doesn't support features available in any modern translation system such as parameters and plural forms.



How does our mechanism work for the report designer? Pretty simple, anywhere you need to translate something you can use:



tr("This is the text I want to translate")

or

tr("{0} out of {1} think this translation system is great!", $F{positive},$F{total})

or you can use plural forms:

trn("One person", "{0} people", $F{people})



In fact, almost all functions in java gettext are implemented. But that wasn't enough, and for all of them we implemented one with configurable locale. So you can use:



tr( new Locale("ca", "ES"), "This text will be translated into Catalan even if the default report locale is in german!") )



Once we got this working we needed a way to extract those texts and we've made it incredibly simple. There are a couple of scripts in the jasper_reports/java directory:



jrxml2pot: Which extracts the texts from the report into a .pot file, easily translatable with any standard tool or even launchpad!

po2properties: Which converts the translated po file into a .properties file.



We should end up with the following files in our report directory:



superreport.jrxml

superreport_ca_ES.properties

superreport_de_DE.properties

...



If a translation isn't available the original text will be printed.



All this is very easy to do, and most importantly, it can be integrated in your modules and translated using launchpad! The drawback of this mechanism is that, due to lack of infrastructure in JasperReports to do this kind of stuff, we had to reimplement the GroovyCompiler and I18nGroovyCompiler was born. This basically means that:




  • You must use groovy as language in your report. That's not much of a problem, as it's possibly the best choice anyway.
  • You can't do a preview of the report inside iReport. This is a more annoying problem. It isn't hard to solve, but let's leave it to most enthusiastic java programmers that read the planet and see if somebody volunteers for that ;-)

Update: Recent tests have shown that some reports take less than half of the time they used with XML backend, so depending on the report performance gains are really important.

Syndicate content