Generate Custom Excel Reports in Odoo
Odoo’s built-in export tool is fine for simple CSV files, but what about professionally formatted Excel reports with company branding, colours, formulas, and charts?
If you’ve ever needed to generate detailed, polished reports from Odoo, this guide is for you. This guide will show you how to export Odoo data to Excel (XLSX) files programmatically via the backend using Python, with full control over the layout and content.
We’ll cover:
- Exporting data from any Odoo model
- Writing XLSX files using xlsxwriter
- Adding styling, formulas, and charts
- Making files downloadable via a wizard pop-up
Prerequisites
- Odoo backend development experience
- Python 3.x installed
- xlsxwriter Python library
Install via:
pip install xlsxwriter
Module Structure
Module Name - custom_export_excel/
├── models/
│ └── export_wizard.py
├── views/
│ └── export_wizard_view.xml
├── __manifest__.py
Python Code
Import Required Libraries
Define the Wizard Model
We use a transient model (wizard) here because the export is a temporary action. It doesn’t need to persist in the database, and it gives the user a quick download interface.
XML View for Wizard
Excel File Generation Method
This method handles the actual Excel file generation. It fetches sales orders, applies formatting, adds totals, and even inserts a visual chart.
Wrapping Up
With this setup, you can now generate professional Excel reports from your Odoo backend with just one click. The reports are dynamic and styled, include totals and charts, and can be easily downloaded via a wizard pop-up.
This solution is ideal for generating business reports, financial statements, or stock analysis sheets from Odoo.