Generating Jasper Reports from several models

Albert Cervera i Areny 5 may. 2010

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: