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.

28 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from openerp import api, SUPERUSER_ID
  6. _logger = logging.getLogger(__name__)
  7. def post_init_hook(cr, registry):
  8. with api.Environment.manage():
  9. env = api.Environment(cr, SUPERUSER_ID, {})
  10. # Recalculate all mass_mailing contacts tracking_email_ids
  11. contacts = env['mail.mass_mailing.contact'].search([
  12. ('email', '!=', False),
  13. ])
  14. emails = contacts.mapped('email')
  15. _logger.info(
  16. "Recalculating 'tracking_email_ids' in "
  17. "'mail.mass_mailing.contact' model for %d email addresses",
  18. len(emails))
  19. for n, email in enumerate(emails):
  20. env['mail.tracking.email'].tracking_ids_recalculate(
  21. 'mail.mass_mailing.contact', 'email', 'tracking_email_ids',
  22. email)
  23. if n % 500 == 0: # pragma: no cover
  24. _logger.info(" Recalculated %d of %d", n, len(emails))