Create Custom Report Odoo 12

Update: this tutorial also works in Odoo 13

Create a custom report on Odoo 12 is little different from Odoo 11. There are several things need to modified from custom report Odoo 11. As previously custom report Odoo 11, I still use hr_attendance report for this example and will display employee attendance summary (recap) with presence and absence data of each employee.

The final result of the report is as shown below.

Final Result Custom Report Odoo 12

Initial preparation.

For initial preparation, you must create a new database and tick “Load demonstration data”, so that there is preliminary data that we can use to test the code. Then install hr_attendance module, this module is a default module from Odoo. And don’t forget to make sure that the wkhtmltopdf 0.12.1 or wkthmltopdf 0.12.5 has been installed.

After installing the hr_attendance module, you can see attendance data with the following demo data is as shown below.

List Attendance Custom Report Odoo 12

Create a wizard model.

Create a wizard model that inherits from TransientModel.

from odoo import models, fields, api

class AttendanceRecapReportWizard(models.TransientModel):
    _name = ''

    date_start = fields.Date(string="Start Date", required=True,
    date_end = fields.Date(string="End Date", required=True,

    def get_report(self):

Create an xml wizard view.

Create a view to display the wizard based on the wizard model above.

    <record model="ir.ui.view" id="attendance_recap_report_wizard">
        <field name="name">HR Attendance Custom Recap Report</field>
        <field name="model"></field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Attendance Recap Report">
                        <field name="date_start"/>
                        <field name="date_end"/>
                    <button name="get_report" string="Get Report" type="object" class="oe_highlight"/>
                    <button string="Cancel" special="cancel"/>

    <act_window id="action_attendance_recap_report_wizard"
                name="Attendance Recap Report"

    <menuitem action="action_attendance_recap_report_wizard"

After creating the wizard, the result is as shown below.

Wizard View Custom Report Odoo 12

Modify wizard model and create a new abstract model.

Modify method get_report() in model, and create a model that inherits from AbstractModel. As you can see below.

# -*- coding: utf-8 -*-

from datetime import datetime

from odoo import models, fields, api

class AttendanceRecapReportWizard(models.TransientModel):
    _name = ''

    date_start = fields.Date(string="Start Date", required=True,
    date_end = fields.Date(string="End Date", required=True,

    def get_report(self):
        """Call when button 'Get Report' clicked.
        data = {
            'ids': self.ids,
            'model': self._name,
            'form': {
                'date_start': self.date_start,
                'date_end': self.date_end,

        # use `module_name.report_id` as reference.
        # `report_action()` will call `_get_report_values()` and pass `data` automatically.
        return self.env.ref('cj_custom_report_v12.recap_report').report_action(self, data=data)

class ReportAttendanceRecap(models.AbstractModel):
    """Abstract Model for report template.

    for `_name` model, please use `report.` as prefix then add `module_name.report_name`.

    _name = 'report.cj_custom_report_v12.attendance_recap_report_view'

    def _get_report_values(self, docids, data=None):
        date_start = data['form']['date_start']
        date_end = data['form']['date_end']
        date_start_obj = datetime.strptime(date_start, DATE_FORMAT)
        date_end_obj = datetime.strptime(date_end, DATE_FORMAT)
        date_diff = (date_end_obj - date_start_obj).days + 1

        docs = []
        employees = self.env['hr.employee'].search([], order='name asc')
        for employee in employees:
            presence_count = self.env['hr.attendance'].search_count([
                ('employee_id', '=',,
                ('check_in', '>=', date_start_obj.strftime(DATETIME_FORMAT)),
                ('check_out', '<=', date_end_obj.strftime(DATETIME_FORMAT)),

            absence_count = date_diff - presence_count

                'presence': presence_count,
                'absence': absence_count,

        return {
            'doc_ids': data['ids'],
            'doc_model': data['model'],
            'date_start': date_start,
            'date_end': date_end,
            'docs': docs,

Create an xml template report.

Last step is to create an xml for template report as needed.

    <record model="report.paperformat" id="paperformat_attendance_recap_report">
        <field name="name"></field>
        <field name="default" eval="True"/>
        <field name="format">A4</field>
        <field name="page_width">0</field>
        <field name="page_width">0</field>
        <field name="orientation">Portrait</field>
        <field name="margin_top">30</field>
        <field name="margin_right">5</field>
        <field name="margin_bottom">10</field>
        <field name="margin_left">5</field>
        <field name="header_line" eval="False"/>
        <field name="header_spacing">20</field>
        <field name="dpi">90</field>

    <report id="recap_report"
            string="Attendance Recap Report"

    <template id="attendance_recap_report_view">
        <t t-call="web.html_container">
            <div class="header" style="border-bottom: 2px solid black">
                <h3 class="text-center">Attendance Recap Report</h3>
                <h4 class="text-center">
                    <t t-esc="date_start"/>
                    <t t-esc="date_end"/>
            <div class="article">
                <table class="table table-condensed table-bordered" style="width: 100%">
                        <th class="text-center" style="width: 70%">Employee</th>
                        <th class="text-center" style="width: 15%">Presence</th>
                        <th class="text-center" style="width: 15%">Absence</th>
                        <t t-foreach="docs" t-as="doc">
                                    <span t-esc="doc['employee']"/>
                                <td class="text-center">
                                    <span t-esc="doc['presence']"/>
                                <td class="text-center">
                                    <span t-esc="doc['absence']"/>
            <div class="footer">
                <div class="row text-center" style="border-top: 1px solid black;">
                    <div class="col col-3 offset-9 text-right">
                        <ul class="list-inline mt-2">
                            <li class="list-inline-item">Page:</li>
                            <li class="list-inline-item">
                                <span class="page"/>
                            <li class="list-inline-item">/</li>
                            <li class="list-inline-item">
                                <span class="topage"/>

That’s it. Please check for full code, or you can download then install the module to try.

If you need another reference about Odoo report, you can check at

That’s it.

Further reads:


2 thoughts on “Create Custom Report Odoo 12”

  1. Pingback: Create Custom Report Odoo 11 - Cak Juice

  2. Pingback: How To Add Images or Barcodes in Odoo Report - Cak Juice

Comments are closed.