Is there an alternative post_init_hook that is executed on module upgrade?
"post_init_hook" in the __manifest__.file is only executed on install, unfortunately. I also tried increasing the module version etc., but no luck.
I need to provide a new version of an existing module, where a new post_init_hook was added. The problem is - it's not executed. But the clients cannot uninstall and reinstall the module without losing data.
There is a way to fix this with the shell, connected to the database you want to update:
from odoo.addons.<you custom addon> import _post_init_hook
_post_init_hook(env)
Use auto_install module (Recommended):
Create a "glue" module that auto-installs when both dependencies exist:
# __manifest__.py
{
'name': 'Your Module - DIN5008 Integration',
'depends': ['your_module', 'l10n_din5008'],
'auto_install': True, # Installs automatically when both deps present
'post_init_hook': 'init_din5008_layout',
}
Interesting, yes, we will add the migration, too.
However, it does not fully solve our problem. The new init hook was added to initialize an optional report view extension. The module extends standard layouts, and optionally din5008 layout. The problem is, if l10n_din5008 is installed afterwards (should not happen, but ...), it would still be missing. So, we might still refactor it to a new module / optional dependency or add a separate check and initialization call. Thank you anyway for the migration hint!