summaryrefslogtreecommitdiff
path: root/addons/mass_mailing/models
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-09-14 16:29:14 +0200
committerThibault Delavallée <tde@odoo.com>2018-09-20 13:02:17 +0200
commit1f6d534f5a5cc1b83e52796fe9bf5cd5cc562dfb (patch)
tree98f9e7e5bccc41bae6e8c4d59a98ae98bcd8fd4c /addons/mass_mailing/models
parent932ac0e42a4f87919eb0bc97849e034fd6bfcf8f (diff)
[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.
Diffstat (limited to 'addons/mass_mailing/models')
-rw-r--r--addons/mass_mailing/models/mass_mailing.py36
1 files changed, 36 insertions, 0 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
#------------------------------------------------------