You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antiun Ingeniería S.L. - Jairo Llopis
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, SUPERUSER_ID
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. def pre_init_hook_for_submodules(cr, model, field):
  8. """Moves images from single to multi mode.
  9. Feel free to use this as a ``pre_init_hook`` for submodules.
  10. :param str model:
  11. Model name, like ``product.template``.
  12. :param str field:
  13. Binary field that had the images in that :param:`model`, like
  14. ``image``.
  15. """
  16. env = api.Environment(cr, SUPERUSER_ID, dict())
  17. with cr.savepoint():
  18. cr.execute(
  19. """
  20. INSERT INTO base_multi_image_image (
  21. owner_id,
  22. owner_model,
  23. storage,
  24. file_db_store
  25. )
  26. SELECT
  27. id,
  28. %%s,
  29. 'db',
  30. %(field)s
  31. FROM
  32. %(table)s
  33. WHERE
  34. %(field)s IS NOT NULL
  35. """ % {"table": env[model]._table, "field": field},
  36. (model,)
  37. )