1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2013-today OpenERP SA (<http://www.openerp.com>)
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>
20 ##############################################################################
22 from openerp.osv import osv, fields
25 class MailComposeMessage(osv.TransientModel):
26 """Add concept of mass mailing campaign to the mail.compose.message wizard
28 _inherit = 'mail.compose.message'
31 'mass_mailing_campaign_id': fields.many2one(
32 'mail.mass_mailing.campaign', 'Mass mailing campaign',
34 'mass_mailing_name': fields.char('Mass Mailing'),
37 def get_mail_values(self, cr, uid, wizard, res_ids, context=None):
38 """ Override method that generated the mail content by creating the
39 mail.mail.statistics values in the o2m of mail_mail, when doing pure
40 email mass mailing. """
41 res = super(MailComposeMessage, self).get_mail_values(cr, uid, wizard, res_ids, context=context)
42 # use only for allowed models in mass mailing
43 if wizard.model not in [t[0] for t in self.pool['mail.mass_mailing']._get_mailing_type()]:
45 if wizard.composition_mode == 'mass_mail' and wizard.mass_mailing_name:
46 list_id = self.pool['mail.mass_mailing.list'].create(
48 'name': wizard.mass_mailing_name,
49 'model': wizard.model,
50 'domain': wizard.active_domain,
52 mass_mailing_id = self.pool['mail.mass_mailing'].create(
54 'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id and wizard.mass_mailing_campaign_id.id or False,
55 'name': wizard.mass_mailing_name,
56 'template_id': wizard.template_id and wizard.template_id.id or False,
58 'mailing_type': wizard.model,
59 'contact_list_ids': [(4, list_id)],
61 for res_id in res_ids:
62 res[res_id]['statistics_ids'] = [(0, 0, {
63 'model': wizard.model,
65 'mass_mailing_id': mass_mailing_id,