summaryrefslogtreecommitdiff
path: root/addons/mass_mailing/models/mail_thread.py
diff options
context:
space:
mode:
authorSébastien Mottet (oms) <oms@odoo.com>2020-03-30 10:42:36 +0000
committerThibault Delavallée <tde@odoo.com>2020-05-19 10:21:28 +0000
commit28734ac268c7ef24c78e32223b9a4398e96cdb93 (patch)
tree70e2d5268d9fd4b5023f45d92b905643f9e77308 /addons/mass_mailing/models/mail_thread.py
parentc142f1628d4e7b13a7de5a8cf0790d7425badc05 (diff)
[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: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/mass_mailing/models/mail_thread.py')
-rw-r--r--addons/mass_mailing/models/mail_thread.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/addons/mass_mailing/models/mail_thread.py b/addons/mass_mailing/models/mail_thread.py
index e1370de2447..ef1aceee749 100644
--- a/addons/mass_mailing/models/mail_thread.py
+++ b/addons/mass_mailing/models/mail_thread.py
@@ -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)