Odoo 11 Development Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

Addon installation

When you install an addon, Odoo checks its list of available addons for an uninstalled addon with the supplied name. It also checks for the dependencies of that addon and, if any, it will recursively install them before installing the addon.

The installation process of a single module consists of the following steps:

  1. If any, run the addon preinit hook
  2. Load the model definitions from the Python source code and update the database structure if necessary (refer to Chapter 5, Application Models, for details)
  3. Load the data files of the addon and update the database contents if necessary (refer to Chapter 7, Module Data, for details)
  4. Install the addon demo data if demo data is enabled in the instance
  5. If any, run the addon postinit hook
  6. Run a validation of the view definitions of the addon
  7. If demo data is enabled and test is enabled, run the tests of the addon (refer to Chapter 8, Debugging and Automated Testing, for details)
  8. Update the module state in the database
  9. Update the translations in the database from the addon's translations (refer to Chapter 12, Internationalization, for details)

The preinit and postinit hooks are defined in the __manifest__.py file using the pre_init_hook and post_init_hook keys, respectively. The value of the key is the name of a Python function, which must be defined in the __init__.py file of the addon module. The preinit (respectively postinit) hook is called with a database cursor (respectively a database cursor and a registry object) and may perform modification in the database to prepare (respectively finalize) the module installation. Note that these are not run when the module is updated (you can use migration steps for this; see the following).