How Does Odoo Load Addons and Modules
Odoo starts loading addons when it receives the first HTTP request.
__call__ method of
http.py file, it calls
to load all addons in the specified addon paths.
It uses a global variable
to track all modules from loaded addons.
For all addon paths passed in Odoo configuration parameters,
it list sorted items including both files and folders in the path.
For each item, it checks whether the
__openerp__.py manifest file
static folder exist. If both exist, it reads the manifest
and remember its addon path. It imports all modules that have a
Finally it sets WSGI middleware for static folders.
This method is called after the above
load_addons method – when
a new registry is created first time for a database name.
It first checks if the database is initialized by checking
ir_module_module table exists. It not initialized,
openerp.modules.db.initialize to initialize
It then calls
RegistryManager.get method for the
It builds a graph from module’s dependency declaration in 9 steps.
Initially the graph is created with the
Step 1: Load
For the graph that only has the
base module, it calls
- import the Python module by calling the
__import__('openerp.addons.' + module_name)to import all modules with a
- create all model classes and instances defined in the module
and keep them in registry; For the
basemodule, there are 96 models such as
registry.pyare used to create model classes/instances and their fields. Now all base models are available from the registry.
Step 2: Mark other modules to be loaded/updated
For modules specified in ‘init’ and ‘update’ parameters, install and upgrade these module and set their state to ‘installed’.
Step 3: Load marked modules
It first calls
load_marked_modules to load modules whose
states is in the list of
['installed', 'to upgrade', 'to remove'].
Add them to graph based their dependencies. The create and
set model classes/instances and fields for models defined in
For update modules, do the same thing for those modules whose state is ‘to install’.
Step 4-9: Finish, clean up and more
- Step 4: Finish and clean up installations.
- Step 5: Remove unused menu items.
- Step 6: Check and remove modules and reset environment and registry manager.
- Step 7: Verify custom views on every model
- Step 8: Call model registry hook – not used by any model
- Step 9: Run post-install module unit tests.