Browse Source

Add uninstall hook to avoid garbage images hanging around after submodule is uninstalled.

12.0-mig-module_prototyper_last
Jairo Llopis 8 years ago
committed by Vladislav Shepilov
parent
commit
01be895270
  1. 12
      base_multi_image/README.rst
  2. 18
      base_multi_image/hooks.py

12
base_multi_image/README.rst

@ -57,18 +57,26 @@ To develop a module based on this one:
* If the model you are extending already had an image field, and you want to
trick Odoo to make those images to multi-image mode, you will need to make
use of the provided :meth:`~.hooks.pre_init_hook_for_submodules`, like
the ``product_multi_image`` module does::
use of the provided :meth:`~.hooks.pre_init_hook_for_submodules` and
:meth:`~.hooks.uninstall_hook_for_submodules`, like the
``product_multi_image`` module does::
from openerp.addons.base_multi_image.hooks import \
pre_init_hook_for_submodules
def pre_init_hook(cr):
"""Transform single into multi images."""
pre_init_hook_for_submodules(cr, "product.template", "image")
pre_init_hook_for_submodules(cr, "product.product", "image_variant")
def uninstall_hook(cr, registry):
"""Remove multi images for models that no longer use them."""
uninstall_hook_for_submodules(cr, registry, "product.template")
uninstall_hook_for_submodules(cr, registry, "product.product")
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/9.0

18
base_multi_image/hooks.py

@ -59,6 +59,24 @@ def pre_init_hook_for_submodules(cr, model, field):
)
def uninstall_hook_for_submodules(cr, registry, model):
"""Remove multi-images for a given model.
:param openerp.sql_db.Cursor cr:
Database cursor.
:param openerp.modules.registry.RegistryManager registry:
Database registry, using v7 api.
:param str model:
Model technical name, like "res.partner". All multi-images for that
model will be deleted
"""
Image = registry["base_multi_image.image"]
ids = Image.search(cr, SUPERUSER_ID, [("owner_model", "=", model)])
Image.unlink(cr, SUPERUSER_ID, ids)
def table_has_column(cr, table, field):
query = """
SELECT %(field)s

Loading…
Cancel
Save