Today I am gonna talk about odoo controller. By using odoo controller you can create front end or web pages that are integrated with our odoo modules



Odoo Web Controller

It means that instead of showing data on CRM or Odoo's typical form or tree view, you can show records or data on web pages. And we will achieve this using custom web controller or odoo controller.

What is web controller and how to use it

Odoo Web Controller is a python class that can be used when we want to render some data into website. By using odoo controller we can show any data/records on web pages or website in any template.

Problem Statement

Now I will show you what we are going to achieve here by using odoo controller. Actually I want to show some graph on web page. The idea is that on a button click i will call an odoo controller and return a template (render) with some dictionary of data. 

So first of all I will create a controller and than its template (You must create a website page or template in order to handle data sent by controller method on the page.) to show graph. To draw a graph I will use "chart.js" library, you can use any of your favorite library. So lets start...

1- Create a controller.


controllers.py

Use of auth='public' parameter in @http.route

Parameter User Login DB Access Access API
user Required According to Access Control List After Login
admin Required According to Admin User After Login
none Not Required No Yes
public Not Required No Yes
2- Create template, to create template create a new file and named it "graph_template.xml". Don't forget to register that newly created xml file into __openerp.py__.


graph_template.xml


Now its time to test our custom controller, go to browser and open "http://localhost:8069/graph/1", remember here "/graph/1" is the route of our custom controller.