Chapter 9 - Odoo 15 Development Book

Mobile App Javascript


Controllers are used to extend and configure or integrate the frontend with the backend in Odoo. If we need to bring any kind of data from the backend(Models) to the frontend, we will have to use the controllers.

Controllers have their own mechanism for extending and inheriting the controller.

Controllers are created by inheriting an existing controller. And route() decorators are used for defining the routes.

class MyController(odoo.http.Controller):
    @route('/respective_url', auth='public')
    def handler(self):
        return stuff()

To override an existing controller override the required method after inheriting the class. And if needed, we can rewire it completely.

class Extension(MyController):
    def handler(self):
        return super(Extension, self).handler()

A method and route will be visible only if use the decorator route(). If the decorator is missing, the method and route will remain unpublished.

When overriding, when the parent class is working all the decorator belonging to all the methods in that class will be combined. Suppose the decorator of the overriding method has no argument, then the previous one will be kept instead of the new one, and if any argument is provided, it will override the previously defined one.

class Restrict(MyController):
    def handler(self):
        return super(Restrict, self).handler()

will change /some_url from public authentication to user (requiring a log-in)



Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message