This question has been flagged
2 Replies
6400 Views

There is an option in the menifest file to call method during module installation. We can mention pre_init and post_init. 

I would like to call one method while upgrading the module as similar to pre_init. because after module gets installed pre_init will not be called. 

Any suggestion for this ?

Why I need this ... 

I have a stored procedure to generate report data quickly which uses postgresql stored procedure, now when there is a slight change in the procedure I would like to update it thourh the module upgrade process. 


There should be some option available to call method during module upgrade as like pre_init and post_init. 


Avatar
Discard
Best Answer

You can call any method during module update by adding function tag in the xml file.

# Add following code in XML file
<function model="sale.order" name="action_custom_method"/>

@api.model
def action_custom_method(self):
# Your code goes here...
return True

This way method will be called after you upgrade the module.

Avatar
Discard
Author

Yes, it make sense, I will try it and let you know. But isn't there any option to call method during update as like pre_init? I am wondering, it should be there.

AFAIK I have never seen such thing for module update. Still, I am not 100% sure.

Author Best Answer

Finally, I got the solution.


We created one .sql file and into that file we added all our stored procedures and other database objects.


We added that sql file in the __manifest__.py


'data': [            
            'db_function/get_product_sales_history_data.sql',
            'db_function/update_product_sales_history.sql',
        ],

It will execute these sql files at the time of module installation as well as module upgrade time.

Avatar
Discard