Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 39 ยท Modules and Business Apps

Module Dependencies and Loading Order

Learn how the depends key shapes Odoo's module graph, how load order is computed, what circular dependencies do, and how glue modules with auto_install work.

Odoo's standard apps are not one big program. They are dozens of small modules stacked on each other: sale depends on account and product, sale_stock depends on both sale and stock, and every module in the system ultimately depends on base. This stack is the module graph, and understanding it explains install errors, the Apps screen and good design habits for your own modules.

In this lesson you learn how Odoo orders modules for loading, what the depends key promises you, and how to split a feature into a core module and optional "glue" modules.

What depends promises

When your manifest says "depends": ["sale"], Odoo guarantees:

  1. sale and all of its own dependencies are installed (they are installed automatically if you press Install on your module).
  2. sale's Python models are loaded and registered before yours, so your classes can extend sale.order.
  3. sale's data files (views, groups, external ids) are loaded before yours, so you can refer to sale.view_order_form.
  4. When sale is updated, Odoo also updates modules that depend on it.

It does not guarantee anything for modules you did not list. If your code uses a model from stock but you only depend on sale, your module works on some databases and crashes on others. Always list every module whose models, views or groups you use, directly.

The module graph

flowchart TB
    base --> mail
    base --> product
    mail --> account
    product --> account
    account --> sale
    product --> stock
    sale --> sale_stock
    stock --> sale_stock
    sale_stock --> vet_shop["your module"]

Arrows go from a dependency to the module that needs it. base is the root of everything.

How the load order is computed

Odoo computes a topological order: a list in which every module appears after all of its dependencies. Several orders may be valid (for example product and mail are independent), but any valid order gives the same result for correct modules. Within the same level, the order is stable (sorted by name and sequence), so two servers behave the same way.

A circular dependency, where A depends on B and B depends on A, has no valid order. Odoo cannot load such modules and reports an error. The fix is always architectural: move the shared part into a third module that both can depend on.

Extending versus depending

Sometimes you want to add a feature to an existing app only if another app is also present. For example, "show stock availability on sales orders" only makes sense when both Sales and Inventory exist. Official Odoo solves this with glue modules (also called bridge modules): a small module sale_stock that depends on both and is installed automatically when both are installed. The manifest key is:

Python
{
    "name": "Sales and Stock Link",
    "depends": ["sale", "stock"],
    "auto_install": True,
    # ... data and so on
}

With auto_install set to True, installing both sale and stock triggers installing the glue module without any click. (It can also be a list in recent versions to say which of the dependencies trigger it; check the documentation of your series.) This keeps sale free from knowledge of stock, and makes each piece optional.

Choosing good dependencies

  • Keep dependencies minimal. Depend on base or on the smallest module that offers what you need. A module depending on sale cannot be installed on a database without Sales.
  • Split by feature, not by technology. A "pet loyalty points" feature belongs in its own module so you can install or remove it as a unit.
  • Use a bridge module for optional integrations.
  • Never edit the core modules of Odoo. Extend them from your own module (chapter 4 shows how); that is why upgrades stay possible.
  • Declare external Python libraries your code imports with the external_dependencies key: {"python": ["requests"]}. Odoo then reports a clear error if the library is missing.

A runnable stand-in: topological order

Python's standard library ships graphlib, which solves the same problem. This stand-in computes a load order for a set of modules and detects a cycle. It is a model of what the Odoo loader does, not its code.

Python Stand-in: compute the load order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A second stand-in: which modules come with an install?

When you install one module, Odoo also installs everything it depends on, and then any glue modules whose dependencies are now all present. This stand-in simulates that "closure".

Python Stand-in: what gets installed together

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first call does not install sale_stock because stock is missing, while the second one does.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Your module uses the stock.picking model but depends only on sale. What is the problem?

    Depend directly on every module whose models, views or groups you use.
  2. 2. What happens with a circular dependency between two modules?

    A cycle cannot be ordered topologically. Move the shared part into a third module.
  3. 3. What does auto_install: True do?

    It is used for glue modules that connect two optional apps.
  4. 4. Where should you declare a pip library your Python code imports?

    external_dependencies lets Odoo check for missing Python packages and give a clear message.

Summary

  • depends ensures the listed modules (and theirs) are loaded and installed before yours.
  • Odoo computes a topological load order; circular dependencies are impossible.
  • List every module you use directly, and keep the list small.
  • Glue modules with auto_install connect optional apps without coupling them.
  • Never edit core modules; extend them from your own.

Next: Data Files and XML IDs