top of page
  • Writer's pictureTek Siong, Hock

Odoo - Wizard to run the report and download to Excel

Sometimes, we can use the wizard to allow the user to select the parameter and download the report result to the Excel.

Start by creating the wizard.

The wizard XML.

<record id="view_warehouse_monthly_form" model="ir.ui.view">
    <field name="name">view.warehouse.monthly.form</field>
    <field name="model"></field>
    <field name="arch" type="xml">
        <form string="Warehouse Monthly Report">
                <field name="date_from"/>
                <field name="date_to"/>
                <field name="cargo_type"/>
                <button string="Export Report" name="export_report" type="object" class="oe_highlight"/>
                <button string="Cancel" class="oe_link" special="cancel" />

Implement the export_report method to search for the result and generate your own excel report name , as well as pass the data to the Excel Report.

class WarehouseReport(models.TransientModel):
    _name = ""

    date_from = fields.Date(string='Start Date',)
    date_to = fields.Date(string='End Date',)
    cargo_type = fields.Selection([('fcl', 'FCL'), ('lcl', 'LCL')], string='Cargo Type')

    def export_report(self):
        domain = [('receipt_date', '>=', self.date_from),
                  ('receipt_date', '<=', self.date_to),
                  ('job_status', 'not in', ['04', '01'])]
        if self.cargo_type:
            domain.append(('cargo_type', '=', self.cargo_type))
        jobsheets = self.env['warehouse.tally.sheet'].search(domain, order="receipt_date asc")
        if jobsheets:
            mylist = []
            for jobsheet in jobsheets:
            report_name = 'Warehouse Monthly - ' + str(self.date_from) + '.xlsx'
            self.env.ref('stock_card_report.action_warehouse_report_xlsx').report_file = report_name
            return self.env.ref('stock_card_report.action_warehouse_report_xlsx').report_action(self,
                data={'mylist': mylist,
                      'date_from': self.date_from.strftime("%d-%m-%Y"),
                      'date_to': self.date_to.strftime("%d-%m-%Y"),

Declare the report in the xml.

<?xml version="1.0" encoding="utf-8"?>
    <report id="action_warehouse_report_xlsx"
            string="Warehouse Report"
            file = "my_module.report_warehouse_xlsx"

Inherit the report.report_xlsx.abstract and implement the generate_xlsx_report.

Loop through the data parameter to populate the excel.

class WarehouseReportXlsx(models.AbstractModel):
    _name = 'report.my_module.report_warehouse_xlsx'
    _inherit = 'report.report_xlsx.abstract'

    def generate_xlsx_report(self, workbook, data, lines):
        sheet = workbook.add_worksheet('Warehouse Report')
    format_header = workbook.add_format({'align': 'left', 'valign': 'vcenter','font_size': 14, 'bold': True})
        sheet.write(0, 0, 'Warehouse Monthly Report', format_header)

680 views1 comment

Recent Posts

See All

1 comentário

Grill Hub Cafe
Grill Hub Cafe
27 de jan. de 2023

can you share the code

bottom of page