Requirements

Before starting, make sure you have:


• Odoo 19 installed and running 


• Access to the Odoo addons directory. The addons path can be found in the Odoo configuration file (odoo.conf) or by checking the running Odoo service in the terminal. The addons path is defined in the configuration file and includes directories such as /odoo/addons and /odoo/custom_addons, where Odoo modules are stored.

Example: addons_path = /odoo/addons,/odoo/custom_addons


Module Structure

Base Structure :


custom_module/

├── models/

│   ├── __init__.py

│   └── custom_model.py

├── security/

│   └── ir.model.access.csv

├── views/

│   └── custom_views.xml

├── __init__.py

├── __manifest__.py

Step 1: Create Module Folder

First, create a new module folder with a suitable name inside your custom addons directory (custom_addons). This folder acts as the root directory of the module and contains all the necessary files required to build a custom module in Odoo.

The custom_addons path must be added to the addons_path in the Odoo configuration file so that Odoo can detect and load the module.

Step 2:Create a manifest File

Create a file named manifest.py inside the custom_module folder. This file defines the basic configuration of the module, such as its name, version, author, category, and dependencies. It also specifies which data files should be loaded by Odoo.


manifest.py File Code

{
    'name': 'Custom Module',
    'version': '1.0',
    'summary': 'Generic Custom Module for Odoo',
    'author': 'Your Name',
    'category': 'Tools',
    'depends': ['base'],
    'data': [
        'security/ir.model.access.csv',
        'views/custom_views.xml',
    ],
    'installable': True,
    'application': True,
}


Step 3: Initialize Module Python Files

init.py :

The init.py file is used to initialize the module. In this file, we import the required directories (such as models) so that Odoo knows which Python files to load when the module starts.

init.py File Code


from . import models

models/init.py

Inside the models folder, we usually define multiple Python files (model classes). The _init_.py inside the models directory explicitly imports each model file.


models/init.py File code


from . import custom_model

Step 4: Create Models (models.py)

In this step, we create a model file to define the structure of the data. A model represents a database table in Odoo and is used to store and manage records.

The model file contains Python code that defines the class, fields, and business logic. The fields represent the columns in the database table. In this example, we define fields such as name, description, amount, and date.

models.py File Code


from odoo import models, fields

class CustomModel(models.Model):
    _name = 'custom.module'
    _description = 'Custom Module'

    name = fields.Char(string='Name', required=True)
    description = fields.Text(string='Description')
    amount = fields.Float(string='Amount')
    date = fields.Date(string='Date')

Step 5: Create Views (XML)

Views define how data is displayed to users in the Odoo interface. We create XML files to design user interface elements such as list () view and form view.

The list view displays multiple records, while the form view is used to create and edit individual records.

custom_views.xml File Code


<odoo>

    <!-- LIST VIEW -->
    <record id="view_custom_module_list" model="ir.ui.view">
        <field name="name">custom.module.list</field>
        <field name="model">custom.module</field>
        <field name="arch" type="xml">
            <list>
                <field name="name"/>
                <field name="description"/>
                <field name="amount"/>
                <field name="date"/>
            </list>
        </field>
    </record>

    <!-- FORM VIEW -->
    <record id="view_custom_module_form" model="ir.ui.view">
        <field name="name">custom.module.form</field>
        <field name="model">custom.module</field>
        <field name="arch" type="xml">
            <form string="Custom Module">
                <sheet>
                    <group>
                        <field name="name"/>
                        <field name="description"/>
                        <field name="amount"/>
                        <field name="date"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ACTION -->
    <record id="action_custom_module" model="ir.actions.act_window">
        <field name="name">Custom Module</field>
        <field name="res_model">custom.module</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- MENU -->
    <menuitem id="menu_custom_root" name="Custom Module"/>

    <menuitem id="menu_custom_module"
              name="Records"
              parent="menu_custom_root"
              action="action_custom_module"/>

</odoo>

Step 6: Add Access Rights (security file)

In this step, we define access rights to control user permissions in the tables. Odoo uses the ir.model.access.csv file to specify which users can read, write, create, and delete records. This helps ensure data security and proper access control within the application.

ir.model.access.csv file.code


id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_custom_model,custom.model,model_custom_module,,1,1,1,1

Step 7: Install the Module in Odoo

After creating all files, restart the Odoo server and install the module.

  • Restart Odoo server
  • Go to Settings 
  • Activate the developer 
  • Go to apps
  • Click "Update Apps List"
  • Search "Custom Module"
  • Click Install


Install the custom module from the Apps menu in Odoo

Written By

Sangeetha T J

Odoo Developer
Rawdah Technology
Kerala, India
📞 +91 8078252055