Skip to content
hiren-serpentcs edited this page Jun 25, 2018 · 12 revisions

Prerequisites:

  1. Install jasper_reports module in Odoo v11.
  2. Download and Install Jasper Studio from here.
  3. Activate Developer mode in Odoo.

Configuring jasper_reports module:

Adding Java path :

  • After installing the jasper_reports module, from Odoo interface, go to
  • Company -> Jasper Configuration and add your Java executable path there.

JAVA PATH

Example :

Creating Jasper Report for Sale Order:

Create Data template from Odoo

  1. To design a jasper report, we will need the data template (.xml) file. For that, go to
    Settings -> Technical -> Jasper Reports -> Create Data Template.
  2. 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.
  3. This will create a Quotation_template.xml file which we will be used for Report Design.

DATA TEMPLATE

Design report in Jasper Studio

Create a Data Adapter

  1. Now we will design our report in Jasper Studio. First, we will create a Data Adapter in Jasper Studio. JASPER STUDIO

DATA ADAPTER

  1. Select XML document in Data Adapter Wizard and click on Next.

DATA ADAPTER XML

  1. 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.

FINISH DATA ADAPTER XML

Design Report

  1. 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.

CREATE REPORT BUTTON

NEW REPORT WIZARD

  1. Give the report file name and save path and click on Next.

REPORT NAME

  1. 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.

DATA SOURCE

  1. Now add the fields which you want in your report and click on Next.

FIELDS

  1. Select the fields that you want to be in a Group (this step is optional) and click Next.

GROUP BY

  1. As you can see, now our report has been created click on Finish.

FINISH

  1. After the report has been loaded, you can now design your report.

STUDIO LAYOUT

  1. You can drag and drop palettes available on the right sidebar.

PALLET

  1. You can drag and drop fields which you have selected from data adapter.

OUTLET

  1. Design the report and save it as “.jrxml” format.

REPORT DESIGN

Print Jasper Report

  1. Now from Odoo interface, go to Settings -> Jasper Reports -> Jasper Reports.

JASPER REPORT MENU

  1. 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.

JASPER FROM VIEW

  1. Attach the jrxml file and set Default to True in order to make it a default report.

ATTACH jrxml FILE

  1. 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.

SAVE RECORD

  1. 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.

PRINT REPORT

Issues and Solutions:

Creating Jasper Report with relation fields:

The following steps demonstrate how to create a Jasper Report with relational fields with an example of Sale Order and Sale Order Line model.

  1. 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.

DATA TEMPLATE

  1. Now create Data Adapter in Jasper Studio with this XML data template.

DATA ADAPTER DATA ADAPTER

  1. Create a new JasperReport with this Data Adapter and add the fields. (It will not show relational fields at the time).

STUDIO LAYOUT

  1. 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.

STUDIO OUTLET STUDIO PROPERTIES

  1. 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

DATA DESIGN

  1. Now you can use these fields in your report.

Print Float values in the 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:

  1. 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.

EXPRESSION EDITOR

  1. 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.

‘uuid’ Error:

#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'

UUID ERROR

This error can be resolved by 2 ways

  1. Open .jrxml file and remove the uuid attribute and it’s value.
  2. Permanent Solution: Open Jasper Studio, go to
    Windows -> Preferences -> Jaspersoft Studio -> Compatibility
    And set Version to JasperReport 3.5.1

JASPER STUDIO CONFIGURATION

Print the Jasper report from button or wizard:

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',
    }

Print the Jasper report with parameter:

In Jasper Report, you can create and print the parameter by doing following steps:

  1. Create a Parameter in your .jrxml file: \
<parameter name="customer_name" class="java.lang.The string"/>
  1. 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>
  1. 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" />
  1. 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',
    }
  1. The output of the report is:

REPORT OUTPUT

Tips and Tricks:

In Jasper Studio, there are bands as shown below

JASPER STUDIO BANDS

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.

PROPERTIES