Create Custom Report


Following are the reporting format supported in OpenERP
  1. rml format
  2. jasper-server
  3. aeroo engine

rml format

In this tutorial we will discuss about creating OpenERP report using RML file. Following are the steps of creating RML file
  • Create SXW file using openoffice. Following are a sample content format of sxw file. (Assume - is [ or ])
. . . . . . . .-- repeatIn(objects, 'o') --
. . . . . . . .Name : -- o.name --
. . . . . . . .Department : -- o.department.name --
. . . . . . . .Admission Date : -- o.adm_date --
. . . . . . . .Age of the Student : -- o.age --
. . . . . . . .Date of Birth : -- o.dob --
      • objects contains the list of object create in the <model>.py
  • Goto <installation path>/openerp7/openerp/addons/base_report_designer/openerp_sxw2rml and type the following command
    • python openerp_sxw2rml <target>.sxw > <destination>.rml
  • Create a python file that can read the rml and display the report in pdf format. following is the sample content
from openerp.report import report_sxw
from openerp.report import *
import time

class admission_slip(report_sxw.rml_parse):
. . . . .def init(self,cursor,user,name,context=None):
. . . . . . . . .super(admission_slip,self)._ _init_ _(cursor,user,name,context=context)
. . . . . . . . . . . . . self.localcontext.update(
. . . . . . . . . . . . . . . . {
. . . . . . . . . . . . . . . . . . . .'time':time,
. . . . . . . . . . . . . . . . }
. . . . . . . . . . . . . )
#report.admission.slip - name that will be use as reference in xml
#college.admission - model name
#college/report/admission_slip.rml' - rml file location
#parser=admission_slip - class name of the report
. . . . .report_sxw.report_sxw('report.admission.slip','college.admission','college/report/admission_slip.rml',parser=admission_slip)
  • Create a xml file as the print view. following is the sample xml
. . . . <?xml version="1.0" encoding="utf-8"?>

. . . . <openerp>
. . . . . . .<data>
. . . . . . .. . <report
. . . . . . . . . . . . auto="True"
. . . . . . . . . . . . .id="admission_slip"
. . . . . . . . . . . . model="college.admission"
. . . . . . . . . . . . name="admission.slip"
. . . . . . . . . . . . rml="college/report/admission_slip.rml"
. . . . . . . . . . . . string="Admission Slip"
. . . . . . . . . . . . header="False"
. . . . . . . . . />
. . . . . . . .</data>
. . . . </openerp>

The id and name must align with the report.sxw parser name and 1st parameter
  • Include the report view xml in the _ _ openerp _ _.py

Notes

  • It is recommended to store the report related files in sub directory of the module
  • Ensure and verify that the rml file contents are correct, especially the parameters of repeatIn. More Info please see the sample code

Sample code