[MIG] mass_mailing_partner: Migration to 15.0

This commit is contained in:
emagdalenaC2i 2022-01-01 16:25:45 +01:00
parent b7fdd5a1c1
commit 9ac22d2db7
3 changed files with 18 additions and 21 deletions

View File

@ -6,7 +6,7 @@
{ {
"name": "Link partners with mass-mailing", "name": "Link partners with mass-mailing",
"version": "14.0.1.0.1", "version": "15.0.1.0.0",
"author": "Tecnativa, " "Odoo Community Association (OCA)", "author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social", "website": "https://github.com/OCA/social",
"license": "AGPL-3", "license": "AGPL-3",

View File

@ -13,21 +13,18 @@ _logger = logging.getLogger(__name__)
def post_init_hook(cr, registry): def post_init_hook(cr, registry):
with api.Environment.manage(): env = api.Environment(cr, SUPERUSER_ID, {})
env = api.Environment(cr, SUPERUSER_ID, {}) # ACTION 1: Match existing contacts
# ACTION 1: Match existing contacts contact_model = env["mailing.contact"]
contact_model = env["mailing.contact"] partner_model = env["res.partner"]
partner_model = env["res.partner"] contacts = contact_model.search([("email", "!=", False)])
contacts = contact_model.search([("email", "!=", False)]) _logger.info("Trying to match %d contacts to partner by email", len(contacts))
_logger.info("Trying to match %d contacts to partner by email", len(contacts)) for contact in contacts:
for contact in contacts: partners = partner_model.search([("email", "=ilike", contact.email)], limit=1)
partners = partner_model.search( if partners:
[("email", "=ilike", contact.email)], limit=1 contact.write({"partner_id": partners.id})
) # ACTION 2: Match existing statistics
if partners: stat_model = env["mailing.trace"]
contact.write({"partner_id": partners.id}) stats = stat_model.search([("model", "!=", False), ("res_id", "!=", False)])
# ACTION 2: Match existing statistics _logger.info("Trying to link %d mass mailing statistics to partner", len(stats))
stat_model = env["mailing.trace"] stats.partner_link()
stats = stat_model.search([("model", "!=", False), ("res_id", "!=", False)])
_logger.info("Trying to link %d mass mailing statistics to partner", len(stats))
stats.partner_link()

View File

@ -9,7 +9,7 @@
<field name="model">mailing.trace</field> <field name="model">mailing.trace</field>
<field name="inherit_id" ref="mass_mailing.mailing_trace_view_form" /> <field name="inherit_id" ref="mass_mailing.mailing_trace_view_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="res_id" position="after"> <field name="message_id" position="after">
<field name="partner_id" /> <field name="partner_id" />
</field> </field>
</field> </field>
@ -20,7 +20,7 @@
<field name="model">mailing.trace</field> <field name="model">mailing.trace</field>
<field name="inherit_id" ref="mass_mailing.mailing_trace_view_tree" /> <field name="inherit_id" ref="mass_mailing.mailing_trace_view_tree" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="sent" position="before"> <field name="sent_datetime" position="before">
<field name="partner_id" /> <field name="partner_id" />
</field> </field>
</field> </field>