In this blog-post you will learn about the modular structure of odoo i.e. What a module consists of, its structure and how it is divided.
Take a look at the module and you will find a specific convention followed to create a module. Each file and folder has a unique purpose and you need to follow the file/folder structure to build your module.
Here is the Odoo Module Directory Structure Diagram,
Let’s dive in and see what each file/folder stands for:
- __init__.py – This file is the initializer of the module. You might have heard about the term ‘constructor’ in java and this file acts in the same way. It contains import statements linking to folders and files in the module.
For e.g. – import models, import wizard etc.
- __openerp__.py – This is the manifest file of the module. It contains various information about your module i.e. Title, Description, Summary etc. You can put some light on the person installing it as why you are building this module, what is the purpose of this module and what your module really does.
- models – This folder contains all your python (.py) files. All the python models (in v8 models.Model) that you create or inherit goes into this directory.
For e.g. – sale.py, crm.py
- views – This folder contains all your view (.xml) files. The view file can contain a form, tree, search views, action etc
- static – Since Odoo 8, website feature is introduced. This folder is basically used to store website related data. It has a subfolder called src and inside src, there are subfolders like,
- js – contains .js files
- img – contains images
- css – stores .css files for designing
- xml – used for qweb templates
- font – font files.
- lib – Used for implementing 3rd party libraries in JS. For e.g. – Combobox library, Google Maps library
- description – It contains an index.html file which is used to give a graphical introduction to your module. Moreover, it contains icon.png which is set as the logo of the module.
- data – Contains data files (.xml files). Sometimes data needs to be inserted along with the module every time the module is installed. You can specify such data in a data file and place it inside this folder. For e.g. Country, States, Unit of Measures
- demo – Contains demo data files (.xml files). This data is useful when you want the user to see a glimpse about how the entries are made in your module. For e.g. Customer invoice, Sale Orders, Quotations. This data is only installed if ‘Load Demo Data’ option is enabled at the time of database creation.
- security – This folder is used to give user roles and permissions. The groups/record rules are defined in an xml file and put in this folder. Moreover, it has ir.model.access.csv file which provides model level security i.e. read, write, create and unlink(delete) permission.
- controller – Basically what a controller does is it gets a request from the client and inquires the server. It gets the work done at the server side and returns back to the client. This folder contains python (.py) files.
- wizard – This folder contains transient models and their views (.py & .xml files). The data is stored temporarily in this model/table and are vacuumed/deleted at regular interval.
- test – Contains .py files to make test cases.
- report – This folder consists of report views (.xml) and parser files (.py).
- workflow – Used to specify a complete business process.
- i18n – means Internationalization, comprises of .po files which are used for translating the text inside your module into several languages. The .po files are named on the basis of the language code. For e.g. – en.po
Hope you learnt about the module structure of odoo, your reviews/comments/suggestions are most welcomed, please comment in the section below, and subscribe to the newsletter to receive timely future updates of this blog.
To learn in-depth about the __init__.py and __openerp__.py file content, Click Here.