Tuesday, March 29, 2011

Creating a Jasper Report using osv_memory in OpenERP 6

I first started using Jasper Report for OpenERP 5. I used a wizard( created using wizard.interface) and the data provided in the wizard is passed to the Jasper Report module and that's it. A well aligned attractive report is created in pdf, xls, html or txt format respective to the report type I provide in the wizard. This works well in openerp-client as well as openerp-web. Then I get a chance to  create the Jasper Report in OpenERP v6. It was simple to change the same jasper report module  of openerp5 to openerp6 and it works fine in openerp-client. But when I opened openrp- web and tried to create the report some unknown characters are printed in the html page and only the html report is working correctly. I spent hours in this issue and then Jabir, one of the hardcore programmer of zbeanz told me that openerp6 had stopped providing support to wizard.interface and told me to use the osv_memory to create the wizard. So I started creating Jasper Report  using osv_memory.

When creating a wizard using osv.osv_memory we need to create a model and view for the wizard, the same process we use to create a  model and view using osv.osv. The main difference inusing osv.osv and osv.osv_memory is that it osv_memory doesnt create tables in the database and osv_memory creates a table in the memory only when the wizard model is active.

If we are creating a multi-stage(multi-state) wizard then each stage depends on the value 'state' defined in the field of the wizard model.




For the state field we have to provide a default value. When we click on the wizard the view depends on this default state. We also have to define some functions that return a value to the next state or returns a value to the report. In my wizard there is only one stage in which when I click on the create button a report(Jasper report ) is created. The function is given below.

Here 'report_name' is the name of the report. This is the place where our jasper report is called. I'm providing the name of the jasper report that is already created myself. At the report module we get the 'datas' from the data. And data['form'] will give all the values provided in the wizard model. Here id and ids are not necessary. 'nodestroy' is for not destroying the wizard when creating the report.

VIEW PART 

Define the record then define form. Inside the form define group for each state.
Inside this group define all the fields that should display in this stage. Then create buttons, one for cancelling the wizard and other for creating the report.

The object type button has the name create_report which is a function defined in the wizard model. After creating the report define the actions and also specify the jasper report file location. Create the menuitem where you want to display the wizard. 

Our wizard creation is now complete and now restart our server and update our module, the new wizard will start working.


note: If anybody have any doubts or need the module I have created fell free to contact me. mail me to omalbastin@gmail.com

Wednesday, March 16, 2011

Jasper Reports- New Era of Reporting in openERP

       Before Jasper Reports, openERP depend mainly on RML reporting for creating reports and RML reports supports pdf and some other formats that are not usually used for reporting. For RML reports, it has so many disadvantages. In RML reports we can add as many rows, but the number of adding columns is fixed. But in Jasper Reports we can add any number of rows and columns. In RML reports we can't add graphics and also can't use expressions for finding values of a field using other field values. These are possible in Jasper reports. 

A customer may need excel reports and html reports. RML reports cant be used for creating excel and html reports. Jasper report does these works. In RML report we cant add graphs, charts, crosstabs, subreports etc. By using Jasper Report we can add graphs, charts, crosstabs, subreports etc. In RML reports we cant add header and footer dynamically. But in Jasper Reports space is provided  title, page header, page footer, column header, column footer, details and summary. Main advantage of using Jasper Report is that jasper report gives more control over data.

Some examples of jasper reports are given below.


Charts-->Pie Chart
The above figure is just a small part of report for user analysis.

Crosstab:
This figure is also a part of report for user analysis.


Creating Jasper Reports- Installation Guide

  Jasper Reports are mainly used for creating stylish reports other than black and white report. We can add tables, charts,crosstabs etc., in to the jasper report and also we can generate different forms of reports like pdf,xls,html etc. For creating Jasper Report, iReport plays an important role. Using ireport we can simply create Jasper Report. I'm using iReport 4.0.1.
        Jasper report and openERP integration can be done by adding jasper_reports module to our openERP server. Now Open the opneERP client. In  customization menu under the administration menu  we can find the a menu for creating jasper report template.
Pop-up window opened for creating data template
Click on it, provide the model name and depth and then click create. Then an xml file wil be generated. This file is needed for the creating Jasper report. Save the file. For now our  work in the openERP client is completed. Now go to iReport open a newblank report template. Change the datasource or create new datasource by clicking on in iReport toolbar. Add a new xml datasource and providing the path of xml file generated from the openerp client.
xml data source configuring
After creating the xml datasource change the query language by clicking on   
 
in the iReport designer bar. Then a window will open for changing the query language.

window for changing query language

These are the basic things to be done for creating a jasper report. Now we can create a module in our openerp server and start creating jasper report.