MVC Architecture & MVC in Odoo ERP

Nilmar Shereef
3 min readNov 12, 2018

--

Every programmer or an IT guy should have heard this term often, at least once in a month. A lot of techies are implementing this ideology without properly understanding the perspective. Here, I would like to go through the topic MVC architecture and how it acts in Odoo ERP.

What is MVC Architecture:

MVC (Model View Controller) is a architectural pattern, commonly used for developing user interfaces that divides an application into three interconnected parts. … The MVC design pattern decouples these major components allowing for efficient code reuse and parallel development”.

Terminologies of MVC

As we know, MVC stands for Model-View-Controller, where

Models: Gets requests from the Controller and sends back data.

Views: Gets data from the Controller and handles rendering.

Controllers: It sends requests to the Model, gets the data back and further passes on appropriate data to the View. It gets and interprets the requests from outside MVC-pattern (client requests).

Image Courtesy:raywenderlich

Real Time Example for MVC

I understand that this definition will not be helpful for a beginner. So, let’s take a real time example before going through the component level description.

Let us assume that you are going to a restaurant for dinner. You will find a table, menu card and eventually make an order for a fresh Avocado juice to the waiter. Here, waiter will take a note of your order and pass it to the kitchen manager (who accepts the order from the waiter). The kitchen manager will pass the item code and quantity to the cook. Here kitchen manager acts like Controller in MVC. All order requests are gathered up by the kitchen manager and necessary instructions are given out.

The cook will parse the order and identifies the necessary ingredients for preparing the dish, i.e. Avocado juice. He brings Avocado and milk from the store room, add water and sugar to prepare the juice. Here, the Cook acts as Model in MVC, because Models provide the data/contents to fulfill the request.

Once the juice is ready, kitchen manager instructs the waiter to serve the item. Thereafter, the waiter presents the item in a way to enhance its aesthetic appeal. He also provides the customer with straws, tissues etc along with it. This is termed as Plating. Here, plating acts as the View in MVC.

MVC in Odoo ERP:

As we know, Odoo ERP is a widely chosen open source business workflow system that is built with Python programming language and PostgreSQL. Here database tables are created with PSQL, general codings are done with Python and views are created through XML. HTML templates are used to build its view in website part. If you look through its skeleton, You can clearly see that it is inscribed in an MVC concept, where

Model : PostgreSQL tables.

View : XML files/ HTML Templates.

Controller : Python Classes and its functions.

When you click on its user interface for a specific operation, corresponding controller will come into action, by which the particular python function will get triggered up and can either communicate with models (built in PostgreSQL) and retrieve the requested data or directly put the data to the view. View will display the data in a human readable form with the help of style sheet enabled XML or HTML templates. This is how Odoo/Open ERP generally using MVC concept in its architecture.

Image Credit: Real Python

Generally, controller fetch the data from Models as per the request and it passess to the View. View will display the retrieved data with its forms.

Moreover the Odoo ERP, Django, Laravel, ERPNext, Flask, Sinatra are the examples that uses MVC concepts.

Hope you got the general idea on MVC Concepts and how it is used in an Enterprise Resource Planning System (ERP System).

Thanks & Regards: Nilmar Shereef

--

--

Nilmar Shereef
Nilmar Shereef

Written by Nilmar Shereef

Sr. Software Engineer/ERP Implementer/Odoo Certified ERP Techno-Functionalist/Python Enthusiast/

Responses (1)