mass_mailing_report.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. from openerp.osv import fields, osv
  3. from openerp import tools
  4. class MassMailingReport(osv.Model):
  5. _name = 'mail.statistics.report'
  6. _auto = False
  7. _description = 'Mass Mailing Statistics'
  8. _columns = {
  9. 'scheduled_date': fields.datetime('Scheduled Date', readonly=True),
  10. 'name': fields.char('Mass Mail', readonly=True),
  11. 'campaign': fields.char('Mass Mail Campaign', readonly=True),
  12. 'sent': fields.integer('Sent', readonly=True),
  13. 'delivered': fields.integer('Delivered', readonly=True),
  14. 'opened': fields.integer('Opened', readonly=True),
  15. 'bounced': fields.integer('Bounced', readonly=True),
  16. 'replied': fields.integer('Replied', readonly=True),
  17. 'state': fields.selection(
  18. [('draft', 'Draft'), ('test', 'Tested'), ('done', 'Sent')],
  19. string='Status', readonly=True,
  20. ),
  21. 'email_from': fields.char('From', readonly=True),
  22. }
  23. def init(self, cr):
  24. """Mass Mail Statistical Report: based on mail.mail.statistics that models the various
  25. statistics collected for each mailing, and mail.mass_mailing model that models the
  26. various mailing performed. """
  27. tools.drop_view_if_exists(cr, 'mail_statistics_report')
  28. cr.execute("""
  29. CREATE OR REPLACE VIEW mail_statistics_report AS (
  30. SELECT
  31. min(ms.id) as id,
  32. ms.scheduled as scheduled_date,
  33. mm.name as name,
  34. mc.name as campaign,
  35. count(ms.bounced) as bounced,
  36. count(ms.sent) as sent,
  37. (count(ms.sent) - count(ms.bounced)) as delivered,
  38. count(ms.opened) as opened,
  39. count(ms.replied) as replied,
  40. mm.state,
  41. mm.email_from
  42. FROM
  43. mail_mail_statistics as ms
  44. left join mail_mass_mailing as mm ON (ms.mass_mailing_id=mm.id)
  45. left join mail_mass_mailing_campaign as mc ON (ms.mass_mailing_campaign_id=mc.id)
  46. GROUP BY ms.scheduled, mm.name, mc.name, mm.state, mm.email_from
  47. )""")