Why ‘pre_init_hook’ on __manifest__.py in Odoo?
By Arunima,

  Category: Odoo     Comments: None

In Odoo, Installation Hooks are used for installation/uninstall of modules.

In the ‘__manifest__.py’ file, we can use these special keys like


  • pre_init_hook
  • post_init_hook
  • uninstall_hook


The value of these keys should be a string and  representing the name of a function defined inside  module’s __init__.py.


Here we discuss about ‘pre_init_hook’.


pre_init_hook is called with  a cursor and  modify database to prepare for the installation of the module.It is commonly used for compatibility checking of modules.

We can use ‘pre_init_hook’  for executing the logic before registering a module in ‘ir.module.module’.That means, it is executed before completing the installation process.


  1. Validated that the module is build for Odoo 11.
  • Define ‘pre_init_hook’ key in yourpy


  “pre_init_hook” :”pre_init_check”,


  • Value of the key must be a function name which is defined in py

def pre_init_check(cr):

from odoo.service import common

from odoo.exceptions import Warning

version_info = common.exp_version()

server_serie = version_info.get(‘server_serie’)

if server_serie != ‘11.0’:

raise Warning(

‘Module support Odoo series 11.0, found                                                   {}.’.format(server_serie))

return True



  1. Delete the record from the database.
    • In py file
       ‘pre_init_hook’: ‘pre_init_hook’,


.  In  __init__.py file



from odoo import api, SUPERUSER_ID


# TODO: Apply proper fix & remove in master

def pre_init_hook(cr):

env = api.Environment(cr, SUPERUSER_ID, {})


(‘model’, ‘like’, ‘%stock%’),

(‘module’, ‘=’, ‘stock’)



Leave a Reply

Notify of