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.

36 lines
1.4 KiB

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