How to Develop a Custom App for Odoo 18

Developing a custom app in Odoo can empower your business by adding specific functionalities and streamlining workflows unique to your needs. In this guide, we’ll go through the process of creating a custom app in Odoo 18, starting from setting up the app structure to defining models, views, and menus.

Why Create a Custom App in Odoo?

Odoo’s flexibility allows you to add or modify features without disturbing the core functionality. Custom apps are:

  1. Modular and Independent: They keep customizations separate from Odoo's core code, making maintenance and upgrades easier.
  2. Reusable: You can package and reuse your custom app across different Odoo instances.
  3. Scalable: They grow with your business needs as you add more functionalities.

Prerequisites

To create a custom app in Odoo, you’ll need:

  • Odoo 18 Installed: Ensure you have Odoo 18 installed and running.
  • Developer Mode Enabled: Developer Mode is necessary for creating custom modules.
  • Basic Knowledge of Python and XML: Familiarity with these languages is helpful since they’re used for coding and defining views.
  • Admin Access: Access to Odoo's file structure on the server.

Step 1: Plan Your Custom App

For this example, let’s create an app called Employee Directory. This app will store employee details like name, contact information, department, and job title. It’s a useful way for businesses to organize employee data and make it easily accessible.

Step 2: Set Up the Module Structure

  1. Navigate to Your Odoo Addons Directory: Open the directory where Odoo modules are stored (usually /odoo/addons).
  2. Create a Folder for Your App: Name it something meaningful, like employee_directory.
  3. Directory Structure: Inside this folder, create the following file structure:
    employee_directory/
    ├── __init__.py
    ├── __manifest__.py
    └── models/
        ├── __init__.py
        └── employee.py
    └── views/
        └── employee_views.xml
    

Step 3: Define the Manifest File

The manifest file (__manifest__.py) is essential for Odoo to recognize your app. It provides metadata about the app, like its name, description, and dependencies. Create this file with the following content:

# employee_directory/__manifest__.py

{
    'name': 'Employee Directory',
    'version': '1.0',
    'category': 'Human Resources',
    'summary': 'Manage employee details in an organized manner.',
    'description': 'An app to store and view employee contact details, job titles, and departments.',
    'author': 'Your Name',
    'depends': ['base'],  # Base module dependency
    'data': [
        'views/employee_views.xml',  # The XML file for views
    ],
    'installable': True,
    'application': True,
}

Explanation:

  • depends: Lists other Odoo modules your app relies on; base is often the minimum requirement.
  • data: Lists XML files that define views or other data.

Step 4: Define the Model for Employee Details

Now, let’s define the main model for the Employee Directory app. This model will hold the employee details.

  1. Open employee.py and add the following code:
# employee_directory/models/employee.py

from odoo import models, fields

class Employee(models.Model):
    _name = 'employee.directory'  # Unique model name for the Employee Directory
    _description = 'Employee Directory'

    name = fields.Char(string='Name', required=True)
    email = fields.Char(string='Email')
    phone = fields.Char(string='Phone')
    job_title = fields.Char(string='Job Title')
    department = fields.Char(string='Department')

Explanation:

  • _name: Specifies the model’s unique identifier. It must be unique across the system.
  • fields.Char: Defines character fields for name, email, phone, job title, and department.
  • string: Provides a label for each field that will display in the UI.
  • Update __init__.py in the models folder to make sure Odoo loads the model:
# employee_directory/models/__init__.py

from . import employee
  1. In the root __init__.py, include the models folder:
# employee_directory/__init__.py

from . import models

Step 5: Define the Views in XML

Views define how data is presented to users in the Odoo interface. Create the XML file employee_views.xml inside the views folder with the following code:

<!-- employee_directory/views/employee_views.xml -->

<odoo>
    <record id="view_employee_form" model="ir.ui.view">
        <field name="name">employee.directory.form</field>
        <field name="model">employee.directory</field>
        <field name="arch" type="xml">
            <form string="Employee">
                <sheet>
                    <group>
                        <field name="name"/>
                        <field name="email"/>
                        <field name="phone"/>
                        <field name="job_title"/>
                        <field name="department"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="view_employee_tree" model="ir.ui.view">
        <field name="name">employee.directory.tree</field>
        <field name="model">employee.directory</field>
        <field name="arch" type="xml">
            <tree string="Employee Directory">
                <field name="name"/>
                <field name="job_title"/>
                <field name="department"/>
            </tree>
        </field>
    </record>

    <menuitem id="menu_employee_directory" name="Employee Directory" sequence="1"/>
    <menuitem id="submenu_employee" name="Employees" parent="menu_employee_directory" action="action_employee_list"/>

    <record id="action_employee_list" model="ir.actions.act_window">
        <field name="name">Employees</field>
        <field name="res_model">employee.directory</field>
        <field name="view_mode">tree,form</field>
    </record>
</odoo>

Explanation:

  • Form View (view_employee_form): Specifies the layout when viewing individual employee records.
  • Tree View (view_employee_tree): Defines the layout for the list view of employees.
  • Menu Items: Creates a top-level menu for “Employee Directory” and a submenu “Employees.”
  • Action (action_employee_list): Defines the action to display employee records in a list or form view.

Step 6: Install and Test Your Custom App

  1. Restart Odoo: Restart the Odoo service to register the new module.
  2. Activate Developer Mode: In Settings, activate Developer Mode if it’s not already enabled.
  3. Update Apps List: Go to Apps, then Update Apps List to refresh the available modules.
  4. Install the App: Find Employee Directory in the Apps list and click Install.
  5. Test the App: Go to Employee Directory > Employees and test adding, viewing, and editing employee records.

Conclusion

You’ve successfully created a custom app in Odoo 18! This basic Employee Directory app demonstrates the core steps involved in developing an Odoo module from scratch, including setting up the module structure, defining a model, creating views, and adding menus. With this foundation, you can extend your app further by adding features, customizing views, or implementing access controls as needed.

Custom app development in Odoo empowers you to adapt Odoo to fit your exact business processes. As you grow more comfortable with Odoo’s framework, you can build increasingly sophisticated modules to boost productivity and streamline operations.

How to Add a Field to an Existing Model in Odoo 18 by Developing a Custom Module