-
Notifications
You must be signed in to change notification settings - Fork 145
Documentation
- Install jasper_reports module in Odoo v11.
- Download and Install Jasper Studio from here.
- Activate Developer mode in Odoo.
- After installing the jasper_reports module, from Odoo interface, go to
- Company -> Jasper Configuration and add your Java executable path there.
- To design a jasper report, we will need the data template (.xml) file. For that, go to
Settings -> Technical -> Jasper Reports -> Create Data Template. - For example, if we want to create Jasper Report for Sale Order, we will select Quotation model and give the depth of 2 and click on Create.
- This will create a Quotation_template.xml file which we will be used for Report Design.
- Now we will design our report in Jasper Studio. First, we will create a Data Adapter in Jasper Studio.
- Select XML document in Data Adapter Wizard and click on Next.
- Give the Data Adapter name, select the data template XML file which was generated from Odoo and check on Use the report XPath expression when filling the report (It will create XPath which will be used for the report in Odoo) and click on finish.
- Now that we have a Data Adapter, we will design the report with the help of it. Click on New JasperReport from the menu and select the report size and design and click on Next.
- Give the report file name and save path and click on Next.
- Select the Data Adapter which we created and double click on the record in the node (this will get all the fields of the record) and click on Next.
- Now add the fields which you want in your report and click on Next.
- Select the fields that you want to be in a Group (this step is optional) and click Next.
- As you can see, now our report has been created click on Finish.
- After the report has been loaded, you can now design your report.
- You can drag and drop palettes available on the right sidebar.
- You can drag and drop fields which you have selected from data adapter.
- Design the report and save it as “.jrxml” format.
- Now from Odoo interface, go to Settings -> Jasper Reports -> Jasper Reports.
- Create a new record and fill the appropriate fields. Jasper Report gives the feature that you can print the report in many formats available in Jasper Output field.
- Attach the jrxml file and set Default to True in order to make it a default report.
- Save the record and go to the Sale Order and open the record that you want to print the report for and click on the print menu.
- You will find the option there with the name you defined for report click on that option and the report will be printed as per given format.
The following steps demonstrate how to create a Jasper Report with relational fields with an example of Sale Order and Sale Order Line model.
- Create the Data Template with the depth of 2. Because if we set depth = 1 it takes only first child fields and if we increased depth it increases child hierarchy.
- Now create Data Adapter in Jasper Studio with this XML data template.
- Create a new JasperReport with this Data Adapter and add the fields. (It will not show relational fields at the time).
- Now select the main report element from outline panel in the left sidebar and find the Edit Query, filter and sort options button from Properties panel on the right sidebar.
- Here you can see all the fields including relational fields too. You can drag the required field and drop it to the fields tab given below it. The below panel shows the fields which were included at the time of creating the report from the data adapter
- Now you can use these fields in your report.
In Jasper Report, when you try to print the float value, it will be printed in 0.000000 formats and Jasper takes all fields as a string so we have to convert that field from string to float. To do that, you can follow these steps:
- Go to Jasper Studio and double click on the field that you want to convert into the float. It will open Expression editor of the field.
- Now to convert it to a float value, we have to replace it with
Float.valueOf( $F{ field_name} )
Ex.Float.valueOf( $F{Unit_Price-price_unit} )
This will convert the value to 0.0 format.
If you want to convert it to 0.00 format, we can replace it with
String.format("%.2f", Float.parseFloat($F{field_name}))
Ex. String.format("%.2f", Float.parseFloat($F{Unit_Price-price_unit}))
And click on Finish.
#53 solves the uuid error by updating the libraries.
When you find the following error : Attribute 'uuid' is not allowed to appear in element 'jasperReport'
This error can be resolved by 2 ways
- Open .jrxml file and remove the uuid attribute and it’s value.
- Permanent Solution: Open Jasper Studio, go to
Windows -> Preferences -> Jaspersoft Studio -> Compatibility
And set Version to JasperReport 3.5.1
You can print the report from button or wizard by creating a method that returns a dictionary with the type of ir.actions.the report, report_name, and report_type as Jasper.
For example, In your xml file, you can define a button as follows:
<button string='Print Invoice' name="print_invoice" type="object" class="btn-primary"/>
And the method should be as follows:
def print_invoice(self):
context = dict(self._context)
context['active_ids'] = self._context.get('active_ids', [])
return {
'type': 'ir.actions.report',
'context': context,
'report_name': 'Jasper Invoice',
'report_type': 'jasper',
}
In Jasper Report, you can create and print the parameter by doing following steps:
- Create a Parameter in your .jrxml file: \
<parameter name="customer_name" class="java.lang.The string"/>
- Print the parameter in your jrxml file: \
<textField isBlankWhenNull="true">
<reportElement x="63" y="16" width="200" height="20" />
<textElement verticalAlignment="Middle">
<font size="13"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$P{order_name}]]></textFieldExpression>
</textField>
- Now we have to define a button in Odoo .xml file:
<button name="print_jasper_sale_order" type="object" class="btn-info" string="Print Sale Order" />
- And the method which will be called is:
def print_jasper_sale_order(self):
data = {}
data.update({'parameters': {
'customer_name': self.partner_id.name,
'order_name': self.name,
}
})
return {
'data': data,
'type': 'ir.actions.report',
'report_name': 'sale_order_report_with_parameter',
'report_type': 'jasper',
}
- The output of the report is:
In Jasper Studio, there are bands as shown below
By default, the record in detail band is set to be repeated so if want to print the record which has more than one value than you have to put it in Detail 1 band.
- If you want to print the value only once in detail band, you can do it by Select that field than go to its property in the right sidebar, find and uncheck the Print Repeated Values checkbox.