Skip to content
Snippets Groups Projects
Commit 28734ac2 authored by Sébastien Mottet (oms)'s avatar Sébastien Mottet (oms) Committed by Thibault Delavallée
Browse files

[IMP] mass_mailing: propagate UTM on replies


USE CASE

Send a mailing to some recipients. Set reply-to of this mailing to an alias
creating records on a model inheriting from utm.mixin. UTM informations on
mailing are not propagated to the newly-created records.

SPECIFICATIONS

When an user answers to a mail of a mailing with an alias creating records
on an UTM enabled model, propagate UTM from the mailing to the new record.

In order to set UTM informations during record creation, "message_new" has
been overridden in mass_mailing. That way it is automatically available on
all models inheriting from utm.mixin.

A test simulating this scenario has been added. It checks if UTMs info are
correctlwy set on the created record by comparing them to the mailing's UTM
info.

Task Id 2210334

closes odoo/odoo#48602

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent c142f162
No related branches found
No related tags found
No related merge requests found
......@@ -62,3 +62,26 @@ class MailThread(models.AbstractModel):
blacklist_rec = self.env['mail.blacklist'].sudo()._add(bounced_email)
blacklist_rec._message_log(
body='This email has been automatically blacklisted because of too much bounced.')
@api.model
def message_new(self, msg_dict, custom_values=None):
""" Overrides mail_thread message_new that is called by the mailgateway
through message_process.
This override updates the document according to the email.
"""
defaults = {}
if issubclass(type(self), self.pool['utm.mixin']):
thread_references = msg_dict.get('references', '') or msg_dict.get('in_reply_to', '')
msg_references = tools.mail_header_msgid_re.findall(thread_references)
if msg_references:
traces = self.env['mailing.trace'].search([('message_id', 'in', msg_references)], limit=1)
if traces:
defaults['campaign_id'] = traces.campaign_id.id
defaults['source_id'] = traces.mass_mailing_id.source_id.id
defaults['medium_id'] = traces.mass_mailing_id.medium_id.id
if custom_values:
defaults.update(custom_values)
return super(MailThread, self).message_new(msg_dict, custom_values=defaults)
......@@ -15,6 +15,15 @@ class MailingSimple(models.Model):
email_from = fields.Char()
class MailingUTM(models.Model):
""" Model inheriting from mail.thread and utm.mixin for checking utm of mailing is caught and set on reply """
_description = 'Mailing: UTM enabled to test UTM sync with mailing'
_name = 'mailing.test.utm'
_inherit = ['mail.thread', 'utm.mixin']
name = fields.Char()
class MailingBLacklist(models.Model):
""" Model using blacklist mechanism for mass mailing features. """
_description = 'Mailing Blacklist Enabled'
......
......@@ -9,3 +9,5 @@ access_mailing_performance_all,access.mailing.performance.all,model_mailing_perf
access_mailing_performance_user,access.mailing.performance.user,model_mailing_performance,base.group_user,1,1,1,1
access_mailing_performance_blacklist_all,access.mailing.performance.blacklist.all,model_mailing_performance_blacklist,,0,0,0,0
access_mailing_performance_blacklist_user,access.mailing.performance.blacklist.user,model_mailing_performance_blacklist,base.group_user,1,1,1,1
access_mailing_test_utm_all,access.mailing.test.utm.all,model_mailing_test_utm,,0,0,0,0
access_mailing_test_utm_user,access.mailing.test.utm.user,model_mailing_test_utm,base.group_user,1,1,1,1
......@@ -3,6 +3,7 @@
from odoo.addons.test_mass_mailing.tests.common import TestMassMailCommon
from odoo.addons.test_mass_mailing.data.mail_test_data import MAIL_TEMPLATE
from odoo.tests.common import users
class TestMailingInternals(TestMassMailCommon):
......@@ -74,3 +75,48 @@ class TestMailingInternals(TestMassMailCommon):
self.assertEqual(mailing.delivered, 3)
self.assertEqual(mailing.opened, 2)
self.assertEqual(mailing.replied, 2)
@users('user_marketing')
def test_mailing_trace_utm(self):
""" Test mailing UTMs are caught on reply"""
self._create_mailing_list()
self.test_alias.write({
'alias_model_id': self.env['ir.model']._get('mailing.test.utm').id
})
source = self.env['utm.source'].create({'name': 'Source test'})
medium = self.env['utm.medium'].create({'name': 'Medium test'})
campaign = self.env['utm.campaign'].create({'name': 'Campaign test'})
subject = 'MassMailingTestUTM'
mailing = self.env['mailing.mailing'].create({
'name': 'UTMTest',
'subject': subject,
'body_html': '<p>Hello ${object.name}</p>',
'reply_to_mode': 'email',
'reply_to': '%s@%s' % (self.test_alias.alias_name, self.test_alias.alias_domain),
'keep_archives': True,
'mailing_model_id': self.env['ir.model']._get('mailing.list').id,
'contact_list_ids': [(4, self.mailing_list_1.id)],
'source_id': source.id,
'medium_id': medium.id,
'campaign_id': campaign.id
})
mailing.action_put_in_queue()
with self.mock_mail_gateway(mail_unlink_sent=False):
mailing._process_mass_mailing_queue()
traces = self.env['mailing.trace'].search([('model', '=', self.mailing_list_1.contact_ids._name), ('res_id', 'in', self.mailing_list_1.contact_ids.ids)])
self.assertEqual(len(traces), 3)
# simulate response to mailing
self.gateway_reply_wrecord(MAIL_TEMPLATE, self.mailing_list_1.contact_ids[0], use_in_reply_to=True)
self.gateway_reply_wrecord(MAIL_TEMPLATE, self.mailing_list_1.contact_ids[1], use_in_reply_to=False)
mailing_test_utms = self.env['mailing.test.utm'].search([('name', '=', 'Re: %s' % subject)])
self.assertEqual(len(mailing_test_utms), 2)
for test_utm in mailing_test_utms:
self.assertEqual(test_utm.campaign_id, campaign)
self.assertEqual(test_utm.source_id, source)
self.assertEqual(test_utm.medium_id, medium)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment