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.

33 lines
1.0 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 SUPERUSER_ID
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. def post_init_hook_for_submodules(cr, registry, model, field):
  8. """Moves images from single to multi mode.
  9. Feel free to use this as a ``post_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. with cr.savepoint():
  17. records = registry[model].search(
  18. cr,
  19. SUPERUSER_ID,
  20. [(field, "!=", False)],
  21. context=dict())
  22. _logger.info("Moving images from %s to multi image mode.", model)
  23. for r in registry[model].browse(cr, SUPERUSER_ID, records):
  24. _logger.debug("Setting up multi image for record %d.", r.id)
  25. r.image_main = r[field]