Generating Jasper Reports from several models
Quick summary
The article explains how to build Jasper reports that start from one model while displaying related data from another. The solution is to use a subreport and configure the `OPENERP_PATH_PREFIX` property with the path from the main model to the subreport model; in the example, the prefix is `order_line/product_id`.
Contents
When you need to create a new report using the jasper_reports module, you must use as base model the one in the screen where you want the button to be displayed.
For example, if you want a report that displays all product information, including its picture, in a brochure, the model will be product.product and the report button will be displayed on that model.
What if you want a button in a quotation to print the brochures of all products in the current quotation? Until now, there were three possibilities: create a new report with sale.order as its base model, create a wizard, or create a relate button that opens a new tab with all products in the quotation.
We implemented a new way to solve this problem using Jasper Reports. Create a new report with sale.order as its base model, insert a subreport embedding the brochure report, and add the OPENERP_PATH_PREFIX property to specify the path from the current model (sale.order) to the subreport model (product.product). In this example, the prefix path is order_line/product_id.
The following screenshot shows where to add the property using iReport:

Frequently asked questions
Which model should be used as the base for a new `jasper_reports` report?
Use as the base model the one belonging to the screen where the report button should appear. For example, if the button must appear on a product, the base model is product.product.
How can the brochures for all products in a quotation be printed?
Create the report with sale.order as its base model and insert a subreport containing the product-brochure report.
What is `OPENERP_PATH_PREFIX` used for?
It specifies the path from the current model to the subreport model so that Jasper can access the related data. In the quotation example, the path is order_line/product_id.
What alternatives were available before this approach?
The alternatives were to create a new report based on sale.order, create a wizard, or add a relation button that opened a new tab with all the products in the quotation.
Related articles
Developer
Translations and user information in Jasper Reports
The `jasper_reports` module adds a virtual User relation so reports can access information about the person running them, even when the document is not related to a company. It also supports designing and previewing translations in iReport with `i18ngroovy`, the required libraries and the `tr()` functions.
ERP and Business
Accounting reports with Jasper
The `account_jasper_report` module provides Journal, Trial Balance, General Ledger and VAT Register reports for OpenERP v6. According to the article, it dramatically reduces accounting-report generation time and requires the latest version of `jasper_reports`.
Developer
jasper_reports NG
jasper_reports NG improves report performance by avoiding repeated Java virtual machine starts and making XML-based reports up to 10% faster. It also expands localisation with translatable fields, parameters, plural forms and locale selection, together with tools for extracting and preparing translations.