4
votes

I am trying to write a customize Odoo module which need to call some form of PRE-installation or POST-installation function / hook , wandering any of you have this knowledge which can share with me how to go about it ?

Sample of process : e.g. During installation , when user click to install the custom module , it will call a Pre-installation hook and do some initialization, copying of files or other and then after that once it finished , we can capture the return installation process of Odoo and run a Post-installation hook. And it will only execute once during the time where the module install / upgrade.

Do appreciate to share a pointer of where this Pre / Post installation code should go into my module code ?

Thanks Kalmen

1

1 Answers

2
votes

You just need to add a hooks.py file to your module. Then in your __openerp__.py file add the hooks you want to execute:

"post_init_hook": "post_init_hook",
"pre_init_hook": "pre_init_hook",

Then in the file write the methods to update the records you want, you can use the orm and execute queries, for example:

def pre_init_hook(cr, registry):
    cr.execute('ALTER TABLE res_partner'
               'ADD COLUMN new_column character varying;')
    cr.execute('UPDATE new_column'
               'SET new_column = phone;')
    # in the installation the column phone is dropped

def post_init_hook(cr, registry):
    partners = env['res.partner'].search([])
    for partner in partners:
        if partner.new_column:
           #do something
    cr.execute('select new_column from res_partner')