Enable Dark Mode!
By: Sahla Sherin

How to Create a Module in Odoo 16

Functional Odoo 16

The Odoo module is used to add new business logic or improve existing business logic. Now we are going to discuss how to create a new basic Odoo module in Odoo 16.

An Odoo module has a structure to keep the elements inside a module. As we already discussed, the structure of the Odoo module is in another blog.

Link: An Overview of Module Structure in Odoo 16

To create a module, we can use the scaffold command. This command automatically creates an empty module.

./odoo-bin scaffold module_name custom_addons_location

As I said above, we need to create a manifest file that contains two init files. To contain the Python models, we have to create a directory called models


class GymMembership(models.Model):
   _name = "gym.membership"
   _inherit = ["mail.thread", "mail.activity.mixin"]
   _description = "Gym Membership"
   _rec_name = "reference"
   reference = fields.Char(string='GYM reference',required=True,readonly=True, default=lambda self: _('New'))
   member_id = fields.Many2one('res.partner', string='Member', required=True,tracking=True,
   domain="[('gym_member', '!=',False)]")
   membership_scheme_id = fields.Many2one('product.product',
                                       string='Membership scheme',
                                       required=True, tracking=True,
                                       domain="[('membership_date_from', '!=',False)]")
   paid_amount = fields.Integer(string="Paid Amount", tracking=True)
   membership_fees = fields.Float(string="Membership Fees", tracking=True,
   sale_order_id = fields.Many2one('sale.order', string='Sales Order',
                                   ondelete='cascade', copy=False,
   membership_date_from = fields.Date(string='Membership Start Date',
                                      help='Date from which membership becomes active.')
   membership_date_to = fields.Date(string='Membership End Date',
                                    help='Date until which membership remains active.')
   company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True,
                                default=lambda self: self.env.company)

Here we import the needed modules and packages. Now we get a table and fields to store the value.

Add this to the init file

From . import membership

And also the model to the init of the module directory.

from . import models

To get a user interface, we need to define the views for that Odoo using XML files. So we have to define the menu and submenu. Gym Management menu and Membership submenu. 


<menuitem id="gym_management_root"
         name="Gym Management"

Now we can define the views like kanban, list, form, etc in the XML file. Currently, here we are defining the form and tree. Also, here we initially define the tree view and form view.

<record id="view_membership_tree" model="ir.ui.view">
   <field name="name">gym.membership.tree</field>
   <field name="model">gym.membership</field>
   <field name="arch" type="xml">
       <tree default_order="reference desc">
           <field name="reference"/>
           <field name="member_id"/>
           <field name="membership_scheme_id"/>
           <field name="membership_fees"/>
           <field name="state"/>
<record id="view_membership_form" model="ir.ui.view">
   <field name="name">gym.membership.form</field>
   <field name="model">gym.membership</field>
   <field name="arch" type="xml">
               <field name="state" widget="statusbar"
               <div class="oe_title">
                       <field name="reference"/>
                       <field name="member_id"/>
                       <field name="paid_amount"/>
                       <field name="membership_fees"/>
                       <field name="sale_order_id" readonly="1"/>
                       <label for="membership_date_from" string="Membership Duration"/>
                       <div class="o_row">
                           <field name="membership_date_from" required="1"/>
                           <field name="membership_date_to" required="1"/>
           <div class="oe_chatter">
               <field name="message_follower_ids"/>
               <field name="activity_ids"/>
               <field name="message_ids"/>

If you need, then you can add a security file, group, record rule, etc. According to your requirements. These files are used for access rights.


To know more about access right https://www.cybrosys.com/blog/security-groups-access-rights-in-odoo-16

Add the path of this module in the manifest file, go-to apps, and upgrade, and then our custom module is there in the apps.

How to Create a Module in Odoo 16-cybrosys

Install the module, and now you can find this module on the menu.

How to Create a Module in Odoo 16-cybrosys

Now you can see the parent menu in the Gym Management. Click on that. Then you get the submenu member and other defined submenus.

How to Create a Module in Odoo 16-cybrosys

Here are the defined fields. You can fill in the details accordingly. 

How to Create a Module in Odoo 16-cybrosys

If you have made any changes in the XML file, then don’t forget to upgrade the module. 

How to Create a Module in Odoo 16-cybrosys

Click on this, and you will get the option to upgrade. If you have done any updates in Python, don’t forget to restart the service.

How to Create a Module in Odoo 16-cybrosys

If you want to add Icon for the module, then add icon.png in static->description->icon.png

In module info, you get details of the module given in the manifest file.

How to Create a Module in Odoo 16-cybrosys

Like this, you can create and alter modules in Odoo 16. 

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message