[IMP] [ADD] mass_mailing: added a wizard to create new segments.

It can be called directly from within the campaign form view, using a button.
It allows to easily create new segments and launch the composer.

bzr revid: tde@openerp.com-20130912100909-ofalececxn64a389
This commit is contained in:
Thibault Delavallée 2013-09-12 12:09:09 +02:00
parent f5639479db
commit f8922d6b16
9 changed files with 233 additions and 6 deletions

View File

@ -75,7 +75,7 @@ class mail_compose_message(osv.TransientModel):
if 'active_domain' in context: # not context.get() because we want to keep global [] domains if 'active_domain' in context: # not context.get() because we want to keep global [] domains
result['use_active_domain'] = True result['use_active_domain'] = True
result['active_domain'] = '%s' % context.get('active_domain') result['active_domain'] = '%s' % context.get('active_domain')
else: elif not result.get('active_domain'):
result['active_domain'] = '' result['active_domain'] = ''
# get default values according to the composition mode # get default values according to the composition mode
if composition_mode == 'reply': if composition_mode == 'reply':

View File

@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution
# Copyright (C) 2013-today OpenERP SA (<http://www.openerp.com>) # Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -37,6 +37,7 @@
'mass_mailing_demo.xml', 'mass_mailing_demo.xml',
'mail_mail_view.xml', 'mail_mail_view.xml',
'wizard/mail_compose_message_view.xml', 'wizard/mail_compose_message_view.xml',
'wizard/mail_mass_mailing_create_segment.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
], ],
'js': [], 'js': [],

View File

@ -23,6 +23,7 @@ from datetime import datetime
from dateutil import relativedelta from dateutil import relativedelta
from openerp import tools from openerp import tools
from openerp.tools.translate import _
from openerp.osv import osv, fields from openerp.osv import osv, fields
@ -104,6 +105,23 @@ class MassMailingCampaign(osv.Model):
), ),
} }
def launch_segment_create_wizard(self, cr, uid, ids, context=None):
ctx = dict(context)
ctx.update({
'default_mass_mailing_campaign_id': ids[0],
})
return {
'name': _('Create a Segment for the Campaign'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.mass_mailing.segment.create',
'views': [(False, 'form')],
'view_id': False,
'target': 'new',
'context': ctx,
}
class MassMailingSegment(osv.Model): class MassMailingSegment(osv.Model):
""" MassMailingSegment models a segment for a mass mailign campaign. A segment """ MassMailingSegment models a segment for a mass mailign campaign. A segment

View File

@ -19,6 +19,10 @@
<field name="model">mail.mass_mailing.campaign</field> <field name="model">mail.mass_mailing.campaign</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Mass Mailing Campaign" version="7.0"> <form string="Mass Mailing Campaign" version="7.0">
<header>
<button name="launch_segment_create_wizard" type="object"
class="oe_highlight" string="Create a New Segment"/>
</header>
<sheet> <sheet>
<group> <group>
<field name="name"/> <field name="name"/>
@ -28,6 +32,8 @@
<field name="replied"/> <field name="replied"/>
<field name="bounced"/> <field name="bounced"/>
</group> </group>
<label for="segment_ids"/>
<field name="segment_ids"/>
</sheet> </sheet>
</form> </form>
</field> </field>
@ -114,6 +120,10 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Mass Mailing Segments"> <tree string="Mass Mailing Segments">
<field name="name"/> <field name="name"/>
<field name="sent"/>
<field name="delivered"/>
<field name="opened"/>
<field name="replied"/>
</tree> </tree>
</field> </field>
</record> </record>

View File

@ -20,3 +20,4 @@
############################################################################## ##############################################################################
import mail_compose_message import mail_compose_message
import mail_mass_mailing_create_segment

View File

@ -41,17 +41,21 @@ class MailComposeMessage(osv.TransientModel):
} }
_defaults = { _defaults = {
'use_mass_mailing_campaign': True, 'use_mass_mailing_campaign': False,
} }
def onchange_mass_mail_campaign_id(self, cr, uid, ids, mass_mail_campaign_id, context=None): def onchange_mass_mail_campaign_id(self, cr, uid, ids, mass_mailing_campaign_id, mass_mail_segment_id, context=None):
if mass_mail_segment_id:
segment = self.pool['mail.mass_mailing.segment'].browse(cr, uid, mass_mail_segment_id, context=context)
if segment.mass_mailing_campaign_id.id == mass_mailing_campaign_id:
return {}
return {'value': {'mass_mailing_segment_id': False}} return {'value': {'mass_mailing_segment_id': False}}
def render_message_batch(self, cr, uid, wizard, res_ids, context=None): def render_message_batch(self, cr, uid, wizard, res_ids, context=None):
""" Override method that generated the mail content by adding the mass """ Override method that generated the mail content by adding the mass
mailing campaign, when doing pure email mass mailing. """ mailing campaign, when doing pure email mass mailing. """
res = super(MailComposeMessage, self).render_message_batch(cr, uid, wizard, res_ids, context=context) res = super(MailComposeMessage, self).render_message_batch(cr, uid, wizard, res_ids, context=context)
if wizard.composition_mode == 'mass_mail' and wizard.mass_mailing_segment_id: # TODO: which kind of mass mailing ? if wizard.composition_mode == 'mass_mail' and wizard.use_mass_mailing_campaign and wizard.mass_mailing_segment_id: # TODO: which kind of mass mailing ?
for res_id in res_ids: for res_id in res_ids:
res[res_id]['mass_mailing_segment_id'] = wizard.mass_mailing_segment_id.id res[res_id]['mass_mailing_segment_id'] = wizard.mass_mailing_segment_id.id
return res return res

View File

@ -15,7 +15,7 @@
<div> <div>
<group> <group>
<field name="mass_mailing_campaign_id" <field name="mass_mailing_campaign_id"
on_change="onchange_mass_mail_campaign_id(mass_mailing_campaign_id)" on_change="onchange_mass_mail_campaign_id(mass_mailing_campaign_id, mass_mailing_segment_id, context)"
attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('use_mass_mailing_campaign', '=', False)], attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('use_mass_mailing_campaign', '=', False)],
'required': [('composition_mode', '=', 'mass_mail'), ('use_mass_mailing_campaign', '=', True)]}"/> 'required': [('composition_mode', '=', 'mass_mail'), ('use_mass_mailing_campaign', '=', True)]}"/>
<field name="mass_mailing_segment_id" <field name="mass_mailing_segment_id"

View File

@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
from openerp.osv import osv, fields
from openerp.tools.translate import _
class MailMassMailingSegmentCreate(osv.TransientModel):
"""Wizard to help creating mass mailing segments for a campaign. """
_name = 'mail.mass_mailing.segment.create'
_description = 'Mass mailing segment creation'
_columns = {
'mass_mailing_campaign_id': fields.many2one(
'mail.mass_mailing.campaign', 'Mass mailing campaign',
required=True,
),
'model_id': fields.many2one(
'ir.model', 'Model',
required=True,
),
'model_model': fields.related(
'model_id', 'name',
type='char', string='Model Name'
),
'filter_id': fields.many2one(
'ir.filters', 'Filter',
domain="[('model_id', '=', model_model)]",
),
'domain': fields.related(
'filter_id', 'domain',
type='char', string='Domain',
),
'template_id': fields.many2one(
'email.template', 'Template', required=True,
domain="[('model_id', '=', model_id)]",
),
'segment_name': fields.char(
'Segment name', required=True,
),
'mass_mailing_segment_id': fields.many2one(
'mail.mass_mailing.segment', 'Mass Mailing Segment',
),
}
_defaults = {
}
def on_change_model_id(self, cr, uid, ids, model_id, context=None):
if model_id:
model_model = self.pool['ir.model'].browse(cr, uid, model_id, context=context).model
else:
model_model = False
return {'value': {'model_model': model_model}}
def on_change_filter_id(self, cr, uid, ids, filter_id, context=None):
if filter_id:
domain = self.pool['ir.filters'].browse(cr, uid, filter_id, context=context).domain
else:
domain = False
return {'value': {'domain': domain}}
def create_segment(self, cr, uid, ids, context=None):
""" Create a segment based on wizard data, and update the wizard """
for wizard in self.browse(cr, uid, ids, context=context):
segment_values = {
'name': wizard.segment_name,
'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id.id,
'domain': wizard.domain,
'template_id': wizard.template_id.id,
}
segment_id = self.pool['mail.mass_mailing.segment'].create(cr, uid, segment_values, context=context)
self.write(cr, uid, [wizard.id], {'mass_mailing_segment_id': segment_id}, context=context)
return True
def launch_composer(self, cr, uid, ids, context=None):
""" Main wizard action: create a new segment and launch the mail.compose.message
email composer with wizard data. """
self.create_segment(cr, uid, ids, context=context)
wizard = self.browse(cr, uid, ids[0], context=context)
ctx = dict(context)
ctx.update({
'default_composition_mode': 'mass_mail',
'default_template_id': wizard.template_id.id,
'default_use_mass_mailing_campaign': True,
'default_use_active_domain': True,
'default_active_domain': wizard.domain,
'default_mass_mailing_campaign_id': wizard.mass_mailing_campaign_id.id,
'default_mass_mailing_segment_id': wizard.mass_mailing_segment_id.id,
})
return {
'name': _('Compose Email for Mass Mailing'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(False, 'form')],
'view_id': False,
'target': 'new',
'context': ctx,
}

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Wizard form view -->
<record model="ir.ui.view" id="view_mail_mass_mailing_segment_create_form">
<field name="name">mail.mass_mailing.segment.create.form</field>
<field name="model">mail.mass_mailing.segment.create</field>
<field name="arch" type="xml">
<form string="Create a Mass Mailing Segment" version="7.0">
<group>
<field name="model_model" invisible="1"/>
<field name="domain" invisible="1"/>
<p class="oe_grey" colspan="2"
attrs="{'invisible': [('mass_mailing_campaign_id', '!=', False)]}">
Please choose a mass mailing campaign that will hold the new segment.
</p>
<field name="mass_mailing_campaign_id"/>
<p class="oe_grey" colspan="2"
attrs="{'invisible': ['|', ('model_id', '!=', False), ('mass_mailing_campaign_id', '=', False)]}">
Please choose a model on which you will run the mass mailing.
</p>
<field name="model_id"
on_change="on_change_model_id(model_id, context)"
attrs="{'invisible': [('mass_mailing_campaign_id', '=', False)]}"/>
<p class="oe_grey" colspan="2"
attrs="{'invisible': ['|', ('filter_id', '!=', False), ('model_id', '=', False)]}">
Please choose a filter that will be applied on the model
to find the records on which you will run the mass mailing.
</p>
<field name="filter_id"
on_change="on_change_filter_id(filter_id, context)"
attrs="{'invisible': [('model_id', '=', False)]}"/>
<p class="oe_grey" colspan="2"
attrs="{'invisible': ['|', ('template_id', '!=', False), ('filter_id', '=', False)]}">
Please choose the template to use to render the emails
to send.
</p>
<field name="template_id"
attrs="{'invisible': [('filter_id', '=', False)]}"/>
<p class="oe_grey" colspan="2"
attrs="{'invisible': ['|', ('segment_name', '!=', False), ('template_id', '=', False)]}">
Please choose the name of the campaign segment.
</p>
<field name="segment_name"
attrs="{'invisible': [('template_id', '=', False)]}"/>
<button name="launch_composer" type="object"
string="Create segment and launch email composer"
attrs="{'invisible': [('segment_name', '=', False)]}"/>
</group>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_mail_mass_mailing_segment_create">
<field name="name">Create Mass Mailing Segment</field>
<field name="res_model">mail.mass_mailing.segment.create</field>
<field name="src_model">mail.mass_mailing.campaign</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>