You are on page 1of 27

How to Build Custom

Module in Odoo 15

www.cybrosys.com
INTRODUCTION

❖ In this slide let us see how we can create a new custom module in Odoo 12.

The things covered in the blog are,

a) Creating a new model

b) Creating different views mainly form and tree

c) New Menu etc


❖ In the custom directory which named as ‘custom_addons’. At here, let’s create the custom
module which named as ‘event_management’, Then give the path of custom addons file in the
odoo 15 conf file.
❖ First let’s create the ‘init’ and ‘manifest’ file. Both are python file.
➢ init file- File we have to import all the python files that we are going to use.
➢manifest file- It is the metadata of the module.
❖ So, first of all, let us look at the manifest file and see what its use is.
manifest file, here is the place where we define the details such as the name of the module, its
version, category, author name etc.
* Name – Name of the module to be displayed.

* Version – version of the released module.

* Summary – Summary for the module.

* Category – Category of the module, whether it is sales, purchase, the point of sale etc.

* depends – Suppose if our module depends on any other modules, we have to mention that name
in the depends. As we are going to create a new module and as it is not depending on any other
modules, just add depends as the base.

* data – In the data section, we have to specify all the .xml files here. In our case, we have to
mention the view.xml
❖ Now, let’s create a security folder under the ‘event_management’ module.
❖ In the security folder, we will place the files related to the security. Here we have to create a
csv file inside the security folder. That is, ‘ir.model.access.csv’.
❖ At the ‘csv’ file we can declare the access for each model for which of the users who have the
permission to read, write or edit that particular object.
❖ Then, let’s create the models. Models are the object of this particular module. So where we need to
add the functionality or extend the functionality that can be do in the models file. So let’s create the
directory for models. Under the directory of the model it have python file, First add the ‘init’ file, this is
a required python file under the model directory, where we need to import the python packages or
python file we needed.
❖ Then, We have to create a python file, that we can create the object that we needed for this
custom module. Here i’m creating ‘event.py’.

➢ The first thing we have to do is, import the models folder in the main ‘__init__.py’ file.
 And the created python file, that is, ‘event.py’ import this python file in the inner ‘__init__.py’ file.
❖ So let us move to the ‘event.py’ file that we have imported now. Here in this file, we will define the models and
fields to store the data into the database.So let our model be ‘event.management’, this will create a table in
the database and we have to define the fields to accept the values.
❖ There will be different types of fields, they are Character, Integer, Float, Many2one, Many2many, Boolean etc.
So in our event management record, we need to record the values such as Event Name, Start Date, End
Date, No. of Attendees.
❖ Now we have created the fields. Next, we have to define the view so that it can be seen in the Odoo user
interface.We have to create a directory ‘views’.
❖ Also, We have to create a file inside the folder views, the file is ‘event_view.xml, inside this file, we will define
the menu and the view.
❖ So let us look at how to create an XML file and the menu first.
❖ Here, in the event_view.xml file we have defined two menus, one menu is the main menu named
‘Event Management’ and under that menu, we have created another menu named ‘Event’.
❖ So now on clicking the menu, some action has to take place. So let us look at how the action
can be defined. After defining the action it should be given to the menu.
❖ Now we have defined the action for the menu, if you look at the previous code, you can see that in the
res_model we have given the name of the table we have created in the event.py file, that means on clicking
the menu the action is going to this model.In the view mode, we have specified the views as tree and form.
We have got many other views like kanban, pivot, calendar, etc. But here we are using only tree and
form.Now let us link the above-created action to the menu ‘events’.
❖ Now our event_view.xml will be like this,
❖ Now let us stop defining the view here and add this view to the manifest file that we have
created earlier. Inside the manifest file, you can see a tag data in that you have to add this file.
❖ As the event_view .xml is inside the views folder when specifying the path in the manifest
file. Also added the security file in the ‘manifest’ file. So now the manifest file will be like this,
❖ Now just restart your odoo service and activate the developer mode and click on the Apps ->
Update Apps List -> Update.
❖ Once you click the Update button, search for the module that we have created now, either you can search
using the folder name, which is called the technical name of the module, in our case the technical name of the
module we have created is event management and the name of the module is the name we have given inside
the manifest file which is also Event Management.
❖ Now we can Install the module by clicking the Install button and see what happens. After a few seconds
loading the module will get installed, if it successfully installed it will redirect to home screen else it will show
up an error message. For it installed successfully, to ensure it, come back to apps menu and search our
module and see its status.
❖ Now, you can see the menu named Event Management.
❖ Click on the Event Management menu, you can see a submenu named Event Management.
❖ Here you can create your first event record.
For More
Check our company website for related blogs and Odoo
book.

Details
Odoo Book V15

Check our YouTube channel for functional and technical


videos in Odoo.
How to Build Custom Module in Odoo 15
Thank You

You might also like