You are currently viewing Web Controller in Odoo

Web Controller in Odoo

Odoo web controller having a facility that can create frontend modules integrate with the backend module.


Presently in Odoo, backend modules are accounting, CRM, discuss, helpdesk, hr, sales management, purchase management, inventory, warehouse etc. These modules can be accessed by a user if a user is having permission to access these modules.


Frontend modules are those which refer Odoo website functionalities likewise a website, website sale, website blog etc. With the help of these modules, we also can create website pages with both static and dynamic contents.


Now we will see how we can also create frontend modules with custom web controller that will fetch the data related to company departments and display in the website custom page which we can build using the Odoo web template.


So for this firstly we will create odoo modules. The structure for module is given below.



a]controller – ,

b]view – template.xml

c]data – data.xml





So from a structure, we have to create Odoo module, after that add the below content to create a class in file.


Basically, the file includes the following content-


2]Required import statements

3]Methods to handle business logic


from OpenERP import SUPERUSER_ID

 openerp.addons.web import HTTP

from OpenERP.http import request

class Website_Demo(http.Controller):


@http.route('/department', type='http', auth='user', website=True)

def display_department_data(self):

cr, context, pool =, request.context, request.registry


hr_department = pool.get('hr.department ')

hr_department_ids = hr_department .search(cr, SUPERUSER_ID, [], context=context)

hr_department_data = hr_department .browse(cr, SUPERUSER_ID, hr_department_ids, context=context)


values = {

'department' : hr_department_data


return"website.department ", values)


The @http.route is a decorator used on the method with one required argument. It is meant to handle the request comes to the URL which we have passed in argument.


In the body of a method, you can also add your business logic. Here I have added code to fetch all of the department data. After that, it will render the page with given page template id and values.


You must create a website page in order to handle data sent by the controller method on the page. Similarly, on the website page, you have to add the following content to the template.XML file.


<?xml version="1.0" encoding="utf-8"?>



<template name="Department Details" id="website.department " page="True">

<t t-call="website.layout">

<div id="page">

<h3> Department Details</h3>

<table class="table table-hover">









<t t-foreach="departments" t-as="department">


<td><t t-esc="department .name_related" /></td>

<td><t t-esc="department .working_employee" /></td>












Now website page uses Qweb template engine to render data send by the controller method.


Finally, By using template directives attribute you can render data the on a website page. This way you can create your own custom web controllers. 

If you have any query or looking for custom web controllers, please feel free to contact us

Leave a Reply

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.