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.

37 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  4. # Copyright 2015 Javier Iniesta <javieria@antiun.com>
  5. # Copyright 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 odoo 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.search([('email', '!=', False)])
  17. _logger.info('Trying to match %d contacts to partner by email',
  18. len(contacts))
  19. for contact in contacts:
  20. partners = partner_model.search([
  21. ('email', '=ilike', contact.email)
  22. ], limit=1)
  23. if partners:
  24. contact.write({'partner_id': partners.id})
  25. # ACTION 2: Match existing statistics
  26. stat_model = env['mail.mail.statistics']
  27. stats = stat_model.search([
  28. ('model', '!=', False),
  29. ('res_id', '!=', False),
  30. ])
  31. _logger.info('Trying to link %d mass mailing statistics to partner',
  32. len(stats))
  33. stats.partner_link()