Skip to content

Instantly share code, notes, and snippets.

@GabbasovDinar
Created January 12, 2025 10:50
Show Gist options
  • Save GabbasovDinar/2c220d6adf4e3b6d611d03544c603ca5 to your computer and use it in GitHub Desktop.
Save GabbasovDinar/2c220d6adf4e3b6d611d03544c603ca5 to your computer and use it in GitHub Desktop.
Guidelines for Creating Project Modules in Odoo

Guidelines for Creating Project Modules in Odoo

To ensure scalability, maintainability, and consistency in Odoo projects, follow these guidelines when creating and organizing project-specific modules.


1. Base Module for the Project

Every project should include a dedicated base module. This module serves as the foundation for automating updates across all project modules. By including this base module as a dependency in all other project modules, you can:

  • Automatically trigger updates for all dependent project modules.

This is achieved because every project module depends on the base module. When the base module is updated, all dependent modules are automatically updated as well. This eliminates the need to update each module individually.

Example:

If your project is named "Google Project," the base module could be named:

google_base

In the manifest of other modules, such as google_web_responsive, add:

'depends': ['google_base']

2. Naming Conventions for Modules

Avoiding Name Conflicts

To prevent conflicts with third-party modules, all project-specific modules should begin with the project name. For example:

  • Instead of naming a module web_responsive, name it google_web_responsive.

This avoids issues like conflicting with an OCA module named web_responsive, which might lead to unpredictable system behavior.

Base Module Naming

The base module for the project should follow the same convention:

  • Example: google_base

This approach ensures no conflicts with standard Odoo modules, such as base.

Descriptive Names

Module names should describe their purpose clearly. Examples:

  • google_hr: Customizations for the HR module.
  • google_inventory_management: Specific functionality for inventory management.

3. When to Create New Modules

Guidelines for Creating New Modules

Create a new module when:

  1. The functionality is standalone:

    • The new functionality is logically separate from existing modules.
    • It can operate independently without tightly coupling with other features.
  2. Future scalability:

    • There is a possibility that the functionality may be deprecated, replaced, or removed in the future.
    • Creating a separate module allows for easier uninstallation and maintenance.
  3. Reusability:

    • The functionality might be reused in other projects or installations.
    • A separate module allows for easier adaptation and integration.

Avoid Overloading Existing Modules

Adding unrelated functionality to an existing module increases complexity and makes future maintenance harder. Separate modules allow for clear separation of concerns and modular architecture.

Practical Example:

Instead of adding new inventory workflows into an existing google_base module, create a standalone module like google_inventory_workflows to manage inventory-specific logic.


4. Extending Existing Odoo Modules

When creating a module that extends functionality in a standard Odoo module:

  • Name the new module by prefixing it with the project name.
  • Use the same name as the extended Odoo module for consistency.

Example:

If extending the Odoo sale module, name the new module:

google_sale

This naming convention:

  • Clearly indicates the module's purpose.
  • Prevents conflicts with other custom or third-party modules.
  • Ensures traceability when reviewing or debugging project-specific extensions.

Additional Tips:

  • Clearly document overridden or extended methods to avoid confusion during debugging.
  • Follow Odoo best practices for extending models, views, and workflows.

5. Additional Best Practices

  1. Keep Dependencies Minimal:

    • Avoid adding unnecessary dependencies to maintain a lightweight module structure.
  2. Version Control:

    • Ensure each module includes proper versioning and compatibility details in the manifest.
    • Example: 'version': '16.0.1.0.0'
  3. Documentation:

    • Document the purpose, functionality, and usage of each module in its README file.
    • Use consistent formatting and include installation instructions, usage guidelines, and examples.
  4. Testing:

    • Include automated tests for critical features to ensure reliability during updates.
  5. Code Reviews:

    • Conduct regular code reviews to ensure adherence to project standards and improve code quality.
  6. Uninstall Support:

    • Ensure modules can be cleanly uninstalled by managing data records (e.g., using ondelete='cascade' for related fields).
  7. Consistent Coding Style:

    • Follow Odoo's coding guidelines for Python, XML, and JavaScript.
    • Use linters and formatters (e.g., pylint-odoo) to enforce consistency.

By following these guidelines, you can create well-organized, maintainable, and conflict-free modules for your Odoo projects. This approach ensures smoother deployments, easier updates, and a scalable project architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment