summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorOlivier Dony <odo@odoo.com>2018-07-03 16:34:45 +0200
committerOlivier Dony <odo@odoo.com>2018-07-04 10:11:32 +0200
commita5edf6e0f3f08f8f10043f77c9a4ee653af64b18 (patch)
treeb11284092d0fa1e088eb199f96d956751291d5bd /addons
parentc1de5b84192953e49db04a99106b1c187d622ade (diff)
[IMP] mass_mailing; speed up kanban view
The kanban view displays mailing statistics for all mailings that are sending or done. To compute these statistics, it uses the `total` as the expected number of emails to send. This `total` used to be computed as the number of records matching the mailing filter. This is both slow (filters are seldom written in an optimized way), and incorrect because the recipients were frozen when the email was sent. The number of matching records may have changed since then. To fix both problems, introduce a new `expected` computed field that simply returns the number of emails that were put in queue at the time of sending, and thus represent the real number of expected emails. This field is computed along with the rest of the statistics.
Diffstat (limited to 'addons')
-rw-r--r--addons/mass_mailing/models/mass_mailing.py5
-rw-r--r--addons/mass_mailing/views/mass_mailing_views.xml4
2 files changed, 5 insertions, 4 deletions
diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py
index 83cbce638f7..f6ac8795bd9 100644
--- a/addons/mass_mailing/models/mass_mailing.py
+++ b/addons/mass_mailing/models/mass_mailing.py
@@ -393,6 +393,7 @@ class MassMailing(models.Model):
statistics_ids = fields.One2many('mail.mail.statistics', 'mass_mailing_id', string='Emails Statistics')
total = fields.Integer(compute="_compute_total")
scheduled = fields.Integer(compute="_compute_statistics")
+ expected = fields.Integer(compute="_compute_statistics")
sent = fields.Integer(compute="_compute_statistics")
delivered = fields.Integer(compute="_compute_statistics")
opened = fields.Integer(compute="_compute_statistics")
@@ -433,7 +434,7 @@ class MassMailing(models.Model):
self.env.cr.execute("""
SELECT
m.id as mailing_id,
- COUNT(s.id) AS total,
+ COUNT(s.id) AS expected,
COUNT(CASE WHEN s.sent is not null THEN 1 ELSE null END) AS sent,
COUNT(CASE WHEN s.scheduled is not null AND s.sent is null AND s.exception is null THEN 1 ELSE null END) AS scheduled,
COUNT(CASE WHEN s.scheduled is not null AND s.sent is null AND s.exception is not null THEN 1 ELSE null END) AS failed,
@@ -453,7 +454,7 @@ class MassMailing(models.Model):
m.id
""", (tuple(self.ids), ))
for row in self.env.cr.dictfetchall():
- total = row.pop('total') or 1
+ total = row['expected'] or 1
row['received_ratio'] = 100.0 * row['delivered'] / total
row['opened_ratio'] = 100.0 * row['opened'] / total
row['replied_ratio'] = 100.0 * row['replied'] / total
diff --git a/addons/mass_mailing/views/mass_mailing_views.xml b/addons/mass_mailing/views/mass_mailing_views.xml
index 7395446c67e..36518440f09 100644
--- a/addons/mass_mailing/views/mass_mailing_views.xml
+++ b/addons/mass_mailing/views/mass_mailing_views.xml
@@ -557,7 +557,7 @@
<field name="arch" type="xml">
<kanban>
<field name='color'/>
- <field name='total'/>
+ <field name='expected'/>
<field name='failed'/>
<field name='sent_date'/>
<templates>
@@ -616,7 +616,7 @@
</div>
</div>
<div class='o_kanban_primary_bottom'>
- <field name="delivered" widget="progressbar" title="Delivered" options="{'current_value': 'delivered', 'max_value': 'total', 'editable': false}"/>
+ <field name="delivered" widget="progressbar" title="Delivered" options="{'current_value': 'delivered', 'max_value': 'expected', 'editable': false}"/>
</div>
</t>
</div>