Three Easy Steps to create a Module in Odoo12

- Odoo

How to create a module?

To create a custom module in Odoo 12 below simple steps are needed.

  1. Create a new module
  2. Create a python and xml file with different views
  3. Assign a menu item

Module creation is of two types

  • Inherit or Extend an existing Module
  • Custom Module Creation

Create a new module by creating a new folder and enter the Module Name

In the module folder, create the files like in the above image,

  • Models – Contains the python file

  • Security – Files related to security

  • Views – Xml files that are required

  • __init__.py and __manifest__.py

Starting with the __init__.py file

__init__.py

This file is for importing all the python files used in the module

If we are going to use any python files in the module, firstly, we have to import the models folder in the __init__.py file

Now that we have imported the models folder, now we have import the lead_product.py in the inner __init__.py

All the python files that are used in the module has to be imported in the __init__.py file

Now that we have imported the python file, we will now define the models and fields for the lead_product file

 

The model name is crm.lead and the various fields like name, pdt_crm, price_unit are given with the desired data type

Different field types are given for every field. Like, price_unit is given Float because it refers to the monetary value

Now, a xml file has to be created to define the views for that module. Firstly, the xml file has to be given in the __manifest__.py

 

The lead_product_view.xml file is given in the data field. This means that the xml file is present inside the views folder

Next, the respective view has to be defined so that it can be seen in the odoo user interface.

Create the xml file named lead_product_view.xml in the views folder such that the view and menu can be defined

In the xml file, create a record and define the fields in the tree view by giving the reference of the res_model name given in crm.lead file

The fields are defined in the tree view. The res_model that is used is given such that the fields can be referenced

Now, the window action has to be given for the view

The window action that is given will refer to the view that has to be displayed (ie) this means that, when the menu is clicked, the action will go to this model

Now the above created action has to be lined to the menu TPT Lead menu

<menuitem
id="tpt_crm_menu"
parent="crm_tpt_menu"
name="TPT Leads"
action="tpt_crm_action"/>

The window action has to be defined in the action field along with the parent and the menu item id. The name of the menu also has to be specified

Now, restart the server and Update the Apps List in Odoo by starting the debug mode. Then install the module.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>