ZestyBeanz Technologies Pvt Ltd 4th Floor, Nila, Technopark Thiruvananthapuram,
India – 695581
Phone: +91 471 4063254
Fax : +91 471 2700171


ZestyBeanz Technologies Pvt Ltd
61/3236, Manikkath Cross Road
Ravipuram, Kochi, India - 682016
Phone: +91 484 4063254


Zesty Labs
Office # 2003, Millennium Plaza Building
Sheikh Zayed Rd, Dubai, UAE
Phone: +971 4333 2222​
Mobile: +971-52-7553466


ZestyBeanz Technologies GmbH
Reuterstraße 1
90408 Nürnberg
Fon: +49 911 4801 444
Fax: +49 911 4801 445

MVC in Odoo

Contact Form

Davis Jose's picture

MVC in Odoo

The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components: the model, the view and the controller. Each of these components are built to handle specific development aspects of an application.

MVC is one of the most frequently used industry-standard web development framework to create scalable and extensible projects.

Odoo is built upon a Model-View-Controller (MVC) architecture. One of the primary goals of this architecture is to separate the visual display of the information from the business rules and management of the underlying data. MVC does not replace Web Forms. We can create our Odoo website pages by using the MVC framework. This is true for maintaining flexibility in viewing data.

The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller."

From View to Model : the model sends notification to the view when its data has been modified in order the view to redraw its content. The model doesn't need to know the inner workings of the view to perform this operation. However, the view needs to access the internal parts of the model.

From View to Controller : the reason why the view has limited access to the controller is because the dependencies from the view to the controller need to be minimal: the controller can be replaced at any moment

MVC Model in Odoo

In Odoo, we can apply this model-view-controller semantic with

model : The PostgreSQL tables.
view : views are defined in XML files in Odoo.
controller : The objects of Odoo.

In Building a website in odoo, MVC architecture is heavily used to route ,redirect the pages and  to display data from database.  Also fully developed ecommerce module is also developed based on the workflow of this architecture.

Steps for calling a webpage in odoo website

1. Creating the controller structure

Before you can create (and call) a webpage you need to make a controller. This controller will tell Odoo which URL links to which webpage. Open up your module and create a folder ‘controllers’ if you don’t have one yet. After creating this folder make an __init__ file and add the followig line of code in it
from . import example

1.1 Creating the controller
For loading a website page :
Defining the route in the controller

from odoo import http
from odoo.http import request
class Example(http.Controller):
    @http.route('/example', type='http', auth='public', website=True)
    def  render_example_page(self):
        return http.request.render('module_name.template_id’, {})
In order to let an user navigate to a specific page you will need an @http.route. This @http.route will tell Odoo that we want to link the url ‘/example’ to a specific webpage. Inside the @http.route you will see four variables. Let me explain them one by one:

‘/example’: Because Odoo needs to know which URL links to what (XML) template you’ll need to provide the URL first. In this example it means that http://localhost/example would call this @http.route
type=’http’: This will let Odoo know that your page is running in HTTP.
auth=’public’: Tells Odoo who can view the page.
You can choose between ‘public’, ‘user’ and ‘none’. If you choose ‘public’ anybody can view the page. When you choose ‘user’ only logged in people can view this page and if  you choose ‘none’ there will be no facilities to access the database or any configuration. website=True: Tells Odoo that is has to link to a webpage and that it is not just a Python function.

1.2 Returning the controller function
Finally, you need to return the function. Because the function needs to know which XML record needs to be called we pass it along like this:
return http.request.render('module_name.template_id', {})

http.request.render will call the view renderer from the Odoo framework. within the brackets “()” you have to specify the module_name.page_name. In this case my module is named ‘create_webpage_demo’ and I will create a webpage with the technical name

2. Passing data to the webpage

In the controller we will need to use ‘http.request.env’ to fetch data from a model.
companies = http.request.env[''].sudo().search([])

The website looks at user rights and access rights too you’d need to make sure the users have enough rights. We have  simply add “.sudo()” so that the database query is executed as if it was done by the super administrator user without any security problems. The final thing to do is to pass this data, that is in the variable companies, to the webpage.

@http.route('/companies, type='http', auth='public', website=True)
    def  render_example_page(self):
        companies = http.request.env[''].sudo().search([])
        return http.request.render('module_name.template_id’, {‘companies’:companies})

Because of doing {‘companies’: companies} in the dictionary all data from all companies will be passed along to the webpage.

2.1 Creating the Detail View on Website Page
<template id="detail_page" name="Detail page" page="True">
      <t t-call="website.layout">
        <div class="oe_structure">
          <div class="container">
            <center><h3>Company detail page</h3></center>
            <t t-foreach="companies" t-as="company">
              <h4><span t-esc=""/></h4>
              <table class="table-striped table">
                  <td><span t-esc=""/></td>
                  <td><span t-esc=""/></td>
                    <span t-esc="company.street"/> <span t-esc="company.street2"/><br/>
                    <span t-esc=""/> <span t-esc=""/>
The controller will call this record .so when you would save this and update your module everything will work and passed along the dictionary companies we can access all company data and display in the page.

Creating webpages and using controllers in Odoo is quite easy. As the Odoo framework has a lot of built in libraries (such as requests, less, bootstrap, font awesome, …) it has never been as easy to create webpages as in Odoo 10. As a result you can create beautiful  website pages with beautiful layouts and easily customizable.

apk download's picture

Hi this is about mobile

Hi this is about mobile application website. Here your get alot of mobile application and games which is necessary in mobile and daily life.Here you get apk download

Jewish's picture

Provides multiple learning

Provides multiple learning environment of International standard with holistic system of education at an affordable cost for the successful life of young generation.
paramedical college india
top agriculture College in north india
top agriculture college in dehradun
The goal of the society is to create professionally well skilled students To achieve the said goal, arrangements have been made with the pioneers and front runners both in India and abroad.
best school in premnagar
we all come to work everyday to solve the most basic to the most complex visa related problems
ita canada immigration express entry
Visa Immigration and Citizenship Lawyer in India

토토사이트's picture

I really appreciate this

I really appreciate this wonderful post that you have provided for us. I feel 토토사이트 strongly that love and read more on this topic. I have spent a lot of my spare time reading your content. Thank you a lot.

abc's picture

Welcome to the world of

Welcome to the world of gaming, where life is fast paced and interesting. There is always an adventure waiting for you online.
csgo smurf

agc's picture

We offers end-to-end

We offers end-to-end technical consultancy and know-how as well as know-why to broad spectrum of different requirements of broadcasting industry.
mac pro reseller in delhi
mobile news gathering
radio station consultants in india
mac pro reseller in guwahati
Macbook pro reseller in bhubaneswar
ipad service center in Kolkata

agc's picture

Nice blog, the article you

Nice blog, the article you have shared is good.This article is very useful. My friend suggest me to use this blog.
top school in greater noida

Natasha Cutts's picture

The Internet is based on the

The Internet is based on the system control unit which is called hosting controller. As per the buy writemyessayonline these systems are useful to all the hosting ways. The best thing is that to develop the systems and working in the specific users is in specific country and the areas.

Zatar's picture

Hi Davis, Thanks for this

Hi Davis,
Thanks for this great post, but let me ask one thing please. How is it possible to make the button call the method in the controller directly without having the user to enter the URL manually? To be more clear, how can the user enter some data via a form and invoke a method in the controller which returns some response back to the user.