Odoo Scaffolding
Odoo Scaffolding

Scaffolding in Odoo 17: Building a Strong Foundation

Scaffolding is a powerful method in Odoo 17, designed to expedite the creation of new modules or add-ons with minimal effort. It automatically generates the essential structure for your module, streamlining the initial setup process and allowing you to concentrate on developing the core functionality.

The benefits of utilizing scaffolding are numerous. Firstly, it significantly reduces the time required for initial setup, enabling faster development by eliminating the manual creation of directories, files, and boilerplate code. The resulting modules maintain a consistent structure, adhering to standardized directory and file layouts, facilitating codebase understanding and maintenance.

Scaffolding also minimizes errors by providing pre-populated files with basic configurations, reducing the risk of typos or omitting crucial elements. Additionally, it enhances workflow efficiency by establishing a foundation for common elements like models, views, controllers, and security.

Two Primary Methods For Scaffolding Are Available:

  • CLI Command: The odoo-bin scaffold command allows you to specify the module name and, optionally, a template. The template can either be an existing module in your Odoo instance or a predefined template available through the CLI.

  • Odoo.sh: Within your development environment on Odoo.sh, clicking the “New Module” button and selecting “Default Module Structure” in the wizard automatically generates scaffolding based on Odoo best practices.

Installing the Scaffold Method in Odoo

The scaffold method is a useful tool for Odoo developers who want to create new modules or add-ons quickly and easily. It generates the basic structure and files of a module, such as the manifest file, views, models, and security files. You can then customize the module according to your needs and preferences.
To use the scaffold method, you need to have Odoo installed on your system and run the following command in your terminal:

odoo-bin scaffold <module name> <where to put it>

This will create a subdirectory for your module in the specified location. For example, if you want to create a module named my_module and put it in the addons directory, you can run:

odoo-bin scaffold my_module addons

You can also specify the full path of the location if you want to put the module in a different directory. After running the scaffold command, you will see the following files and directories in your module subdirectory:
  • __init__.py: This file imports the models and controllers of the module.

  • __manifest__.py: This file contains the metadata of the module, such as the name, version, summary, description, dependencies, data files, etc.

  • models: This directory contains the Python files that define the models of the module. You can create your own models or inherit from existing ones.

  • views: This directory contains the XML files that define the views of the module. You can create your own views or inherit from existing ones.

  • controllers: This directory contains the Python files that define the controllers of the module. You can create your own controllers or inherit from existing ones.

  • security: This directory contains the CSV and XML files that define the security rules of the module, such as the access rights, groups, and record rules.

  • static: This directory contains the static files of the module, such as the images, CSS, JS, etc.

  • i18n: This directory contains the translation files of the module, such as the .po and .pot files.

You can edit these files and directories to add your own functionality and features to the module. You can also add more files and directories if you need to. To install the module, you need to restart the Odoo server and update the module list. You can then find the module in the Apps menu and install it.