In this tutorial, i will guide you to create a custom module in Odoo 10. Odoo uses a client-server architecture in which Odoo is the server and the web browser are the clients, which access Odoo using RPC calls. Odoo Modules can either add new business logic or extend the already existing one. Odoo follows a MVC like architecture. And it can be explained as follows.
- Model -- defines the structure.
- View -- defines user interface.
- Controller -- defines business logic.
This tutorial covers only basic knowledge of module creation. So no inheritance and other information are not included.
I have divided the module creation into five tiers for easy understanding.
Odoo follows specific module structure. For easy way to create a skeletal structure of the module you can use the scaffold command
python odoo.py scaffold my_module /path. For more information you can check my guide on Odoo CLI commands here. This will create a basic structure of the module with some sample codes which are commented. Module name must be all small letters and have no space, you can use hyphen instead of space.
In Odoo 10 the descriptor file is named as
__manifest__.py which can be founded at the route of the module, which describes the module information. In older versions this was named as
__openerp__.py. You can use this name, but it is deprecated in the newer version.
If you created your module structure using
scaffold command then there will be some sample data like as follows in
In every module the two important files are
__init__.py. The latter one is used to make the module importable by Odoo. You have to import every python files or folders conatining python files (route __init__.py)inside
__init__.py. If you want to see what Odoo doing with the descriptor file, check this link. I will explain all the descriptor keywords in another tutorial. These two files must be present in your module.
In this phase you have to create business logic files (python files) which contains different fields which are suitable for your application.Example is given below. The file location can be anywhere but i would suggest you to put in the folder
models, either way you have to import it in the
Below is an example of a application data. For more information on the fields that i used in this example, you can check my tutorial on that here. Consider the file name as
Add this file to the
from . import hotel_model. Odoo models are python classes which is added in the central model registry,which is used for later usages by the another models.new models are defined using the
_name ='model name' ,when inheriting a model we can use the
_inherit ="model name".
Models have structural attributes that describes the model such as _name ,_description,_rec_name and _order which are as follows.
Now the business logic has been defined next is defining the view.
There are many types of views in Odoo, right now, we only look at the
tree views. Below is the example of the view definition. Any view that we add, has to be inside the following tag.
Position of the view files can be anywhere. My suggestion is to put it in the
views folder. Consider the file name as
After defining the views we need to add a
menu and an
action to that menu, only after that we can see the defined views in Odoo. Even if you don't define the tree or form view Odoo will create a default tree view for that model with
name as default field.
After creating the views, add this file to the
data with the relative path from module as route. Example
This will create menu called
Hotel in the top menu bar of Odoo, because we didn't add any
parent id in the menu definition. If we want to make it under a certain menu we can add the id of that menu as parent.
Final phase is to install this in Odoo, for that put the created module in the
addons path that you defined in the config file. Then restart the server ,activate the developer mode and go to the apps menu. Update the app list then search for the module that you created and click install.You can see the new
Hotel menu in Odoo. Congratulation..! you have successfully created a custom module.