[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.
This commit is contained in:
@@ -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
|
||||
#------------------------------------------------------
|
||||
|
||||
@@ -534,39 +534,45 @@
|
||||
</div>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button name="%(action_view_mail_mail_statistics_mailing_list)d" type="action"
|
||||
<button name="action_view_sent"
|
||||
type="object"
|
||||
context="{'search_default_filter_sent': True}"
|
||||
icon="fa-envelope-o" class="oe_stat_button o_mass_mailing_button"
|
||||
attrs="{'invisible': ['&', ('sent', '=', 0), ('state', 'in', ('draft','test'))]}" >
|
||||
<field name="sent" string="Emails Sent" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="%(action_view_mail_mail_statistics_mailing_list)d"
|
||||
context="{'search_default_filter_received': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
type="action" class="oe_stat_button">
|
||||
<button name="action_view_delivered"
|
||||
type="object"
|
||||
context="{'search_default_filter_received': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
class="oe_stat_button">
|
||||
<field name="received_ratio" string="Received" widget="percentpie"/>
|
||||
</button>
|
||||
<button name="%(action_view_mail_mail_statistics_mailing_list)d"
|
||||
context="{'search_default_filter_opened': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
type="action" class="oe_stat_button">
|
||||
<button name="action_view_opened"
|
||||
type="object"
|
||||
context="{'search_default_filter_opened': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
class="oe_stat_button">
|
||||
<field name="opened_ratio" string="Opened" widget="percentpie"/>
|
||||
</button>
|
||||
<button name="%(action_view_mail_mail_statistics_mailing_list)d"
|
||||
context="{'search_default_filter_replied': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
type="action" class="oe_stat_button">
|
||||
<button name="action_view_replied"
|
||||
type="object"
|
||||
context="{'search_default_filter_replied': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
class="oe_stat_button">
|
||||
<field name="replied_ratio" string="Replied" widget="percentpie"/>
|
||||
</button>
|
||||
<button name="%(action_view_mass_mailing_links_statistics)d"
|
||||
<button name="action_view_clicked"
|
||||
type="object"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
type="action" class="oe_stat_button">
|
||||
class="oe_stat_button">
|
||||
<field name="clicks_ratio" string="Clicks" widget="percentpie"/>
|
||||
</button>
|
||||
<button name="%(action_view_mail_mail_statistics_mailing_list)d"
|
||||
<button name="action_view_bounced"
|
||||
type="object"
|
||||
context="{'search_default_filter_bounced': True}"
|
||||
attrs="{'invisible': [('state', 'in', ('draft','test'))]}"
|
||||
type="action" class="oe_stat_button">
|
||||
class="oe_stat_button">
|
||||
<field name="bounced_ratio" string="Bounced" widget="percentpie"/>
|
||||
</button>
|
||||
<button name="toggle_active" type="object"
|
||||
|
||||
Reference in New Issue
Block a user