In this tutorial, we are going to create a nice looking sales dashboard with different KPI's for quotations, orders, revenue and average order. We will also add different graphs like bar chart, line chart, pie chart and others. But your'e not limited for these charts since there are a lot more samples that you can use.
We will be using ChartJS Open https://www.chartjs.org/ Free library which is the same what Odoo is using. However, we will be implementing the latest version of ChartJS Open but in the last part of this tutorial, we will be using the same version of Odoo.
We also have date filter that you can select, and once selected, the values will also change as well as the charts will re-render. In addition, clicking each KPI or Chart will redirect you to a specific views with the correct values based on the filter.
Why Create a Custom Dashboard?
I know there's already existing dashboard in Odoo which I believe will cover most of this. However, this tutorial will be beneficial if some specific requirements are needed, like simply changing the colors of the graph, showing different KPI's in a presentable manner, or just by changing the look and feel of a dashboard that will impress your clients right?
Actually, there's a better version of this, by using Odoo Spreadsheet. The values you see above are coming from a spreadsheet module. However, you need to install the Documents module which is available only in Enterprise version. So if you're using community, you're not be able to this.
But maybe your asking, why I have a dashboard here? Well, they did this report using json format under spreadsheet_dashboard_sale module Open . For example the sale dashboard, it's under sales_dashboard.jsonOpen .
The one you see in dashboard sales and product is actually these files. If you open this files, you can see a lot of data regarding the spreadsheet. So it's impossible to just copy this code just to do the same version of Odoo enterprise.
Create New Component and Template
Before we create the component, let's first prepare the necessary files for our custom dashboard module. We need the manifest and init file just to make our module work. But we are not going to use any python code for our custom dashboard. It's pure javascript using OWL Javascript Framework and XML for the menus, client action and OWL templates.
Since KPI cards have all the same layout, instead of creating them into the main template, it's better to create a a sub component and just import it for better code structure. Well this is the idea of components right?
In the above Open sales dashboard componentsales dashboard component, KpiCard component has been imported and then added under components property so that it can be added easily on sales dashboard template using different props (name, value and percentage) with static values.
The same with KPI Cards, the graphs will have the same layout so we need to create a new component and just import it to sales dashbaord component.
Thanks to ChartJS Open https://www.chartjs.org/ free javascript library, we can easily create differnt dashboard by just simply changing the chart type. In order to load this asset, we will be using loadJS method from Odoo. If you want to learn more about using external libraries in Odoo, check this video tutorial Open https://youtu.be/pqN4oJmMRbc.
This chart renderer component will then be imported in sales dashboard component, added as a sub component and will be called in the template with two props (types and title) to render differnt graphs easily.
Alright, so right now we have already created the layout of the sales dashboard. With only a few codes, we are able to reuse these components as many as we want.
For the next tutorial, we are going to add data to each graph based on the values from the database as well as the values for this 4 KPI's with the date filter and if selected any of the filters, the values will automatically change as well as the graph values.
Video Tutorial
To better understand Create Odoo Custom Dashboard From Scratch, kindly check this video version of this tutorial.
Read next article
Odoo Dashbaord Using OWL - ORM & Action Service