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.

38 lines
1.4 KiB

8 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
  3. # © 2015 Antonio Espinosa <antonioea@antiun.com>
  4. # © 2015 Javier Iniesta <javieria@antiun.com>
  5. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  6. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  7. import logging
  8. from openerp import api, SUPERUSER_ID
  9. _logger = logging.getLogger(__name__)
  10. def post_init_hook(cr, registry):
  11. with api.Environment.manage():
  12. env = api.Environment(cr, SUPERUSER_ID, {})
  13. # ACTION 1: Match existing contacts
  14. contact_model = env['mail.mass_mailing.contact']
  15. partner_model = env['res.partner']
  16. contacts = contact_model.with_context(
  17. active_test=False).search([('email', '!=', False)])
  18. _logger.info('Trying to match %d contacts to partner by email',
  19. len(contacts))
  20. for contact in contacts:
  21. partners = partner_model.search([
  22. ('email', '=ilike', contact.email)
  23. ], limit=1)
  24. if partners:
  25. contact.write({'partner_id': partners.id})
  26. # ACTION 2: Match existing statistics
  27. stat_model = env['mail.mail.statistics']
  28. stats = stat_model.search([
  29. ('model', '!=', False),
  30. ('res_id', '!=', False),
  31. ])
  32. _logger.info('Trying to link %d mass mailing statistics to partner',
  33. len(stats))
  34. stats.partner_link()