2017-06-14 20:47:41 +02:00
|
|
|
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
|
|
|
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
|
|
|
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
|
|
|
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
2016-08-08 13:14:37 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
import logging
|
2020-02-10 11:35:23 +01:00
|
|
|
|
|
|
|
from odoo import SUPERUSER_ID, api
|
2016-08-08 13:14:37 +02:00
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def post_init_hook(cr, registry):
|
|
|
|
with api.Environment.manage():
|
|
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
|
|
# ACTION 1: Match existing contacts
|
2020-02-10 11:35:23 +01:00
|
|
|
contact_model = env["mail.mass_mailing.contact"]
|
|
|
|
partner_model = env["res.partner"]
|
|
|
|
contacts = contact_model.search([("email", "!=", False)])
|
|
|
|
_logger.info("Trying to match %d contacts to partner by email", len(contacts))
|
2016-08-08 13:14:37 +02:00
|
|
|
for contact in contacts:
|
2020-02-10 11:35:23 +01:00
|
|
|
partners = partner_model.search(
|
|
|
|
[("email", "=ilike", contact.email)], limit=1
|
|
|
|
)
|
2016-08-08 13:14:37 +02:00
|
|
|
if partners:
|
2020-02-10 11:35:23 +01:00
|
|
|
contact.write({"partner_id": partners.id})
|
2016-08-08 13:14:37 +02:00
|
|
|
# ACTION 2: Match existing statistics
|
2020-02-10 11:35:23 +01:00
|
|
|
stat_model = env["mail.mail.statistics"]
|
|
|
|
stats = stat_model.search([("model", "!=", False), ("res_id", "!=", False)])
|
|
|
|
_logger.info("Trying to link %d mass mailing statistics to partner", len(stats))
|
2016-08-08 13:14:37 +02:00
|
|
|
stats.partner_link()
|