mail_compose_message.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. from openerp.osv import osv, fields
  3. class MailComposeMessage(osv.TransientModel):
  4. """Add concept of mass mailing campaign to the mail.compose.message wizard
  5. """
  6. _inherit = 'mail.compose.message'
  7. _columns = {
  8. 'mass_mailing_campaign_id': fields.many2one(
  9. 'mail.mass_mailing.campaign', 'Mass Mailing Campaign',
  10. ),
  11. 'mass_mailing_id': fields.many2one(
  12. 'mail.mass_mailing', 'Mass Mailing'
  13. ),
  14. 'mass_mailing_name': fields.char('Mass Mailing'),
  15. 'mailing_list_ids': fields.many2many(
  16. 'mail.mass_mailing.list', string='Mailing List'
  17. ),
  18. }
  19. def get_mail_values(self, cr, uid, wizard, res_ids, context=None):
  20. """ Override method that generated the mail content by creating the
  21. mail.mail.statistics values in the o2m of mail_mail, when doing pure
  22. email mass mailing. """
  23. res = super(MailComposeMessage, self).get_mail_values(cr, uid, wizard, res_ids, context=context)
  24. # use only for allowed models in mass mailing
  25. if wizard.composition_mode == 'mass_mail' and \
  26. (wizard.mass_mailing_name or wizard.mass_mailing_id) and \
  27. wizard.model in [item[0] for item in self.pool['mail.mass_mailing']._get_mailing_model(cr, uid, context=context)]:
  28. mass_mailing = wizard.mass_mailing_id
  29. if not mass_mailing:
  30. reply_to_mode = wizard.no_auto_thread and 'email' or 'thread'
  31. reply_to = wizard.no_auto_thread and wizard.reply_to or False
  32. mass_mailing_id = self.pool['mail.mass_mailing'].create(
  33. cr, uid, {
  34. 'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id and wizard.mass_mailing_campaign_id.id or False,
  35. 'name': wizard.mass_mailing_name,
  36. 'template_id': wizard.template_id and wizard.template_id.id or False,
  37. 'state': 'done',
  38. 'reply_to_mode': reply_to_mode,
  39. 'reply_to': reply_to,
  40. 'sent_date': fields.datetime.now(),
  41. 'body_html': wizard.body,
  42. 'mailing_model': wizard.model,
  43. 'mailing_domain': wizard.active_domain,
  44. }, context=context)
  45. mass_mailing = self.pool['mail.mass_mailing'].browse(cr, uid, mass_mailing_id, context=context)
  46. for res_id in res_ids:
  47. res[res_id].update({
  48. 'mailing_id': mass_mailing.id,
  49. 'statistics_ids': [(0, 0, {
  50. 'model': wizard.model,
  51. 'res_id': res_id,
  52. 'mass_mailing_id': mass_mailing.id,
  53. })],
  54. # email-mode: keep original message for routing
  55. 'notification': mass_mailing.reply_to_mode == 'thread',
  56. 'auto_delete': True,
  57. })
  58. return res