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.

20 lines
761 B

  1. # -*- coding: utf-8 -*-
  2. # See README.rst file on addon root folder for license details
  3. from . import models
  4. from . import wizard
  5. from openerp import api, SUPERUSER_ID
  6. def _match_existing_contacts(cr, registry):
  7. with api.Environment.manage():
  8. env = api.Environment(cr, SUPERUSER_ID, {})
  9. contact_model = env['mail.mass_mailing.contact']
  10. partner_model = env['res.partner']
  11. contacts = contact_model.search([('email', '!=', False)])
  12. for contact in contacts:
  13. if contact.email:
  14. partners = partner_model.search([('email', '=ilike',
  15. contact.email)])
  16. if partners:
  17. contact.write({'partner_id': partners[0].id})