From 1f6d534f5a5cc1b83e52796fe9bf5cd5cc562dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 14 Sep 2018 16:29:14 +0200 Subject: [PATCH] [IMP] mass_mailing: redirect to filtered view when clicking on stat buttons Purpose of this commit is to improve user experience in mass mailing by redirecting users on filtered views when clicking on sent / delivered / read / opened / clicked stat buttons. Currently it redirects to the statistics view which is not the most useful one. This commit is linked to task ID 1885121 and closes PR #27003. --- addons/mass_mailing/models/mass_mailing.py | 36 +++++++++++++++++ .../mass_mailing/views/mass_mailing_views.xml | 40 +++++++++++-------- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py index 3fda3483869..2005575b216 100644 --- a/addons/mass_mailing/models/mass_mailing.py +++ b/addons/mass_mailing/models/mass_mailing.py @@ -684,6 +684,42 @@ class MassMailing(models.Model): failed_mails.sudo().unlink() self.write({'state': 'in_queue'}) + def action_view_sent(self): + return self._action_view_documents_filtered('sent') + + def action_view_opened(self): + return self._action_view_documents_filtered('opened') + + def action_view_replied(self): + return self._action_view_documents_filtered('replied') + + def action_view_bounced(self): + return self._action_view_documents_filtered('bounced') + + def action_view_clicked(self): + return self._action_view_documents_filtered('clicked') + + def action_view_delivered(self): + return self._action_view_documents_filtered('delivered') + + def _action_view_documents_filtered(self, view_filter): + if view_filter in ('sent', 'opened', 'replied', 'bounced', 'clicked'): + opened_stats = self.statistics_ids.filtered(lambda stat: stat[view_filter]) + elif view_filter == ('delivered'): + opened_stats = self.statistics_ids.filtered(lambda stat: stat.sent and not stat.bounced) + else: + opened_stats = self.env['mail.mail.statistics'] + res_ids = opened_stats.mapped('res_id') + model_name = self.env['ir.model']._get(self.mailing_model_real).display_name + return { + 'name': model_name, + 'type': 'ir.actions.act_window', + 'view_mode': 'tree', + 'res_model': self.mailing_model_real, + 'domain': [('id', 'in', res_ids)], + 'context': self.env.context, + } + #------------------------------------------------------ # Email Sending #------------------------------------------------------ diff --git a/addons/mass_mailing/views/mass_mailing_views.xml b/addons/mass_mailing/views/mass_mailing_views.xml index b59cf820864..906807cf840 100644 --- a/addons/mass_mailing/views/mass_mailing_views.xml +++ b/addons/mass_mailing/views/mass_mailing_views.xml @@ -534,39 +534,45 @@
- - - - - -