Search Here

How to Use and Create Odoo Web Controller

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.

Post a Comment

12 Comments

  1. Hi,

    I am producing a report to GoogleMaps that plots de service visits done in a day. Right now I am generating a html file the is downloades and then opened with a browser.

    I guess your method is far more elegant, but does it work with odoo8?

    I guess from the python wizard where I generate the info for the report I have to call the controller. How can I do that?

    return xxx ('operaciones.mapre', {
    'fechas': ' '.join(fechas),
    'markers': markers,
    })

    This is the new controller:
    class maps_report(http.Controller):

    @http.route('/mapReport/', auth='user', website=True)
    def generar_map_report(self, cr, uid, fechas, markers, context=None):

    return http.request.render('operaciones.report_mapsservicios', {
    'fechas': ' '.join(fechas),
    'markers':markers,
    })

    ReplyDelete
  2. hello! , it will works on odoo 12?, i want have graphs of my custom modules in the website module, this is possible?

    ReplyDelete
  3. Doesn't work for me in odoo12. Did someone get it to work?

    ReplyDelete
  4. plzzz help me i wana show my model record in a template its not working for me..??

    ReplyDelete
  5. Sir can you tell me how to start opencv with odoo? Is it possible in odoo opencv integration

    ReplyDelete
    Replies
    1. hope this will helps

      https://www.youtube.com/watch?v=tiTud_BlozA

      Delete
  6. Thankyou sir ..gone through this video and installed all required packages but while running code in odoo webcam cam window is not opening but webcam light is opening do you have any idea.

    ReplyDelete