parameters: (self)
docstring: Compute statistics of the mass mailing
docstring_summary: Compute statistics of the mass mailing
docstring_tokens: Compute statistics of the mass mailing
function: def _compute_statistics(self):
          """ Compute statistics of the mass mailing """
          for key in (
              'scheduled', 'expected', 'canceled', 'sent', 'delivered', 'opened',
              'clicked', 'replied', 'bounced', 'failed', 'received_ratio',
              'opened_ratio', 'replied_ratio', 'bounced_ratio',
          ):
              self[key] = False
          if not self.ids:
              return
          # ensure traces are sent to db
          self.flush()
          self.env.cr.execute("""
              SELECT
                  m.id as mailing_id,
                  COUNT(s.id) AS expected,
                  COUNT(s.sent_datetime) AS sent,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'outgoing') AS scheduled,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'cancel') AS canceled,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status in ('sent', 'open', 'reply')) AS delivered,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status in ('open', 'reply')) AS opened,
                  COUNT(s.links_click_datetime) AS clicked,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'reply') AS replied,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'bounce') AS bounced,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'error') AS failed
              FROM
                  mailing_trace s
              RIGHT JOIN
                  mailing_mailing m
                  ON (m.id = s.mass_mailing_id)
              WHERE
                  m.id IN %s
              GROUP BY
                  m.id
          """, (tuple(self.ids), ))
          for row in self.env.cr.dictfetchall():
              total = (row['expected'] - row['canceled']) 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
              row['bounced_ratio'] = 100.0 * row['bounced'] / total
              self.browse(row.pop('mailing_id')).update(row)
function_tokens: def _compute_statistics ( self ) : for key in ( 'scheduled' , 'expected' , 'canceled' , 'sent' , 'delivered' , 'opened' , 'clicked' , 'replied' , 'bounced' , 'failed' , 'received_ratio' , 'opened_ratio' , 'replied_ratio' , 'bounced_ratio' , ) : self [ key ] = False if not self . ids : return # ensure traces are sent to db self . flush ( ) self . env . cr . execute ( """
              SELECT
                  m.id as mailing_id,
                  COUNT(s.id) AS expected,
                  COUNT(s.sent_datetime) AS sent,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'outgoing') AS scheduled,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'cancel') AS canceled,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status in ('sent', 'open', 'reply')) AS delivered,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status in ('open', 'reply')) AS opened,
                  COUNT(s.links_click_datetime) AS clicked,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'reply') AS replied,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'bounce') AS bounced,
                  COUNT(s.trace_status) FILTER (WHERE s.trace_status = 'error') AS failed
              FROM
                  mailing_trace s
              RIGHT JOIN
                  mailing_mailing m
                  ON (m.id = s.mass_mailing_id)
              WHERE
                  m.id IN %s
              GROUP BY
                  m.id
          """ , ( tuple ( self . ids ) , ) ) for row in self . env . cr . dictfetchall ( ) : total = ( row [ 'expected' ] - row [ 'canceled' ] ) 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 row [ 'bounced_ratio' ] = 100.0 * row [ 'bounced' ] / total self . browse ( row . pop ( 'mailing_id' ) ) . update ( row )