From c59039b195c5a9634883ca60ace561c8b818f351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 16 Nov 2021 13:28:52 +0000 Subject: [PATCH] [FIX] mass_mailing: avoid clicks overriding reply trace state Currently if someone replies to a mass mailing email, then performs a click on tracked links, final trace status is set to opened. Indeed both reply and click set the trace as opened, as replying or clicking imply opening the mail. Update is the following * user replies -> set status to open, then set status to reply, and update open_datetime and reply_datetime; * user clicks -> set status to open, then update click_datetime; In the end the trace is left as opened while it is replied, with a click datetime attached to the trace. To avoid unnecessary status update, a trace is set to opened only if it is not already opened or replied. Other statuses should not override themselves. Task-2692316 X-original-commit: ce88d364369c8b58256e8d93b7cb506a2c262a34 Part-of: odoo/odoo#79877 --- addons/mass_mailing/models/mailing_trace.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mass_mailing/models/mailing_trace.py b/addons/mass_mailing/models/mailing_trace.py index 2f12c06c528..ee4d5414f97 100644 --- a/addons/mass_mailing/models/mailing_trace.py +++ b/addons/mass_mailing/models/mailing_trace.py @@ -131,8 +131,11 @@ class MailingTrace(models.Model): return traces def set_opened(self, domain=None): + """ Reply / Open are a bit shared in various processes: reply implies + open, click implies open. Let us avoid status override by skipping traces + that are not already opened or replied. """ traces = self + (self.search(domain) if domain else self.env['mailing.trace']) - traces.write({'trace_status': 'open', 'open_datetime': fields.Datetime.now()}) + traces.filtered(lambda t: t.trace_status not in ('open', 'reply')).write({'trace_status': 'open', 'open_datetime': fields.Datetime.now()}) return traces def set_clicked(self, domain=None):