How to Create a Sample Module Structure in Odoo Using the Scaffold Command in Ubuntu

Odoo provides a built-in command-line utility called Scaffold that allows developers to quickly generate a basic module structure.

Instead of manually creating folders and files such as __init__.py, __manifest__.py, models, views, and other directories, developers can use the scaffold command to generate a sample module template automatically.

This is particularly useful when starting a new custom module in Odoo.

The scaffold command is an Odoo CLI (Command Line Interface) utility used to generate the basic directory structure and template files for a new Odoo module.

It helps developers maintain a standard module structure and reduces the time required for initial module setup.

First, navigate to the directory containing the odoo-bin file.

Command:

cd <ODOO-BIN-PATH>

Then execute the following command:

./odoo-bin scaffold <MODULE-NAME> <PATH-TO-PLACE-MODULE>

Example:

cd /opt/odoo19/odoo
./odoo-bin scaffold test /opt/odoo19/custom-addons

Explanation:

  • ./odoo-bin: Executes the Odoo command-line utility.
  • scaffold: Specifies that a new module structure should be generated.
  • test: Name of the module to be created.
  • /opt/odoo19/custom-addons: Destination directory where the module will be generated.

After executing the command, Odoo creates a folder named test inside the custom-addons directory with the default module structure and template files.

Odoo also provides an option to generate a new module using the structure of an existing module.

For this purpose, you can use the -t option, which specifies the template directory.

Syntax:

./odoo-bin scaffold <MODULE-NAME> -t <PATH-OF-EXISTING-MODULE>

Example:

cd /opt/odoo19/odoo
./odoo-bin scaffold new_module -t /opt/odoo19/custom-addons/test

Explanation:

  • new_module: Name of the newly generated module.
  • -t: Specifies the template option.
  • /opt/odoo19/custom-addons/test: Path of the existing module used as the template.

This allows developers to reuse an existing module’s structure when creating another module.

If Python is installed inside a Odoo virtual environment (odoo-venv), make sure to activate that environment before executing the scaffold command.

If you execute the scaffold command without activating the virtual environment, Odoo may use the system Python interpreter instead of the virtual environment’s Python interpreter which may cause some depend.

How to activate the virtual environment:

source /path/to/venv/bin/activate

For example:

source /opt/odoo19/venv/bin/activate

Once activated, navigate to the Odoo directory and execute the scaffold command:

cd /opt/odoo19/odoo

./odoo-bin scaffold test /opt/odoo19/custom-addons

Using the Odoo scaffold command offers several advantages:

  1. Saves Development Time: Automatically generates the basic module structure without manually creating every file and directory.
  2. Maintains Standard Structure: Helps developers follow Odoo’s standard module organization.
  3. Easy Module Initialization: Provides a starting point for developing custom modules.
  4. Template Reusability: Allows developers to use an existing module structure as a template for new modules.
  5. Reduces Manual Errors: Minimizes mistakes during the initial creation of module files and directories.

The Odoo scaffold command is a simple yet useful development utility for quickly creating custom modules. Whether you are starting a module from scratch or using an existing module as a template, this command makes the initial development setup easier and more efficient.

For Odoo developers working on customizations, understanding CLI commands like scaffold can help improve development productivity.

Leave a Comment

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

Scroll to Top