summaryrefslogtreecommitdiff
path: root/addons/mass_mailing/wizard
diff options
context:
space:
mode:
authorchm@openerp.com <>2014-04-23 17:48:52 +0200
committerchm@openerp.com <>2014-04-23 17:48:52 +0200
commitee7ff4bd07d8d84ed2ebb0e2e3f5eb437f158e5b (patch)
tree25577845139d390f9bf27e0237d18842aeace02b /addons/mass_mailing/wizard
parentb1bc68d8eb374f30173e03e8048d1c3588a00d4b (diff)
parent1657ffb8e7d95ef5f94e59121737abb068371b66 (diff)
[MERGE] from trunk
bzr revid: chm@openerp.com-20140423154852-gzegxqrzb2sj01zl
Diffstat (limited to 'addons/mass_mailing/wizard')
-rw-r--r--addons/mass_mailing/wizard/__init__.py21
-rw-r--r--addons/mass_mailing/wizard/mail_compose_message.py52
-rw-r--r--addons/mass_mailing/wizard/mail_compose_message_view.xml4
-rw-r--r--addons/mass_mailing/wizard/mail_mass_mailing_create_segment.py135
-rw-r--r--addons/mass_mailing/wizard/mail_mass_mailing_create_segment.xml82
-rw-r--r--addons/mass_mailing/wizard/test_mailing.py40
-rw-r--r--addons/mass_mailing/wizard/test_mailing.xml34
7 files changed, 98 insertions, 270 deletions
diff --git a/addons/mass_mailing/wizard/__init__.py b/addons/mass_mailing/wizard/__init__.py
index 669d12289c2..aa8074b7488 100644
--- a/addons/mass_mailing/wizard/__init__.py
+++ b/addons/mass_mailing/wizard/__init__.py
@@ -1,23 +1,4 @@
# -*- 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/>
-#
-##############################################################################
+import test_mailing
import mail_compose_message
-import mail_mass_mailing_create_segment
diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py
index 4b3f0d6b9bd..4aebff2d04d 100644
--- a/addons/mass_mailing/wizard/mail_compose_message.py
+++ b/addons/mass_mailing/wizard/mail_compose_message.py
@@ -1,23 +1,4 @@
# -*- 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
@@ -29,11 +10,14 @@ class MailComposeMessage(osv.TransientModel):
_columns = {
'mass_mailing_campaign_id': fields.many2one(
- 'mail.mass_mailing.campaign', 'Mass mailing campaign',
+ 'mail.mass_mailing.campaign', 'Mass Mailing Campaign',
),
'mass_mailing_id': fields.many2one(
- 'mail.mass_mailing', 'Mass mailing',
- domain="[('mass_mailing_campaign_id', '=', mass_mailing_campaign_id)]",
+ 'mail.mass_mailing', 'Mass Mailing'
+ ),
+ 'mass_mailing_name': fields.char('Mass Mailing'),
+ 'mailing_list_ids': fields.many2many(
+ 'mail.mass_mailing.list', string='Mailing List'
),
}
@@ -42,23 +26,27 @@ class MailComposeMessage(osv.TransientModel):
mail.mail.statistics values in the o2m of mail_mail, when doing pure
email mass mailing. """
res = super(MailComposeMessage, self).get_mail_values(cr, uid, wizard, res_ids, context=context)
- if wizard.composition_mode == 'mass_mail' and wizard.mass_mailing_campaign_id: # TODO: which kind of mass mailing ?
- if wizard.mass_mailing_id:
- mass_mailing_id = wizard.mass_mailing_id.id
- else:
- current_date = fields.datetime.now()
+ # use only for allowed models in mass mailing
+ if wizard.composition_mode == 'mass_mail' and \
+ (wizard.mass_mailing_name or wizard.mass_mailing_id) and \
+ wizard.model in [item[0] for item in self.pool['mail.mass_mailing']._get_mailing_model(cr, uid, context=context)]:
+ mass_mailing = wizard.mass_mailing_id
+ if not mass_mailing:
mass_mailing_id = self.pool['mail.mass_mailing'].create(
cr, uid, {
- 'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id.id,
- 'name': '%s-%s' % (wizard.mass_mailing_campaign_id.name, current_date),
- 'date': current_date,
- 'domain': wizard.active_domain,
+ 'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id and wizard.mass_mailing_campaign_id.id or False,
+ 'name': wizard.mass_mailing_name,
'template_id': wizard.template_id and wizard.template_id.id or False,
+ 'state': 'done',
+ 'mailing_type': wizard.model,
+ 'mailing_domain': wizard.active_domain,
}, context=context)
+ mass_mailing = self.pool['mail.mass_mailing'].browse(cr, uid, mass_mailing_id, context=context)
for res_id in res_ids:
+ res[res_id]['mailing_id'] = mass_mailing.id
res[res_id]['statistics_ids'] = [(0, 0, {
'model': wizard.model,
'res_id': res_id,
- 'mass_mailing_id': mass_mailing_id,
+ 'mass_mailing_id': mass_mailing.id,
})]
return res
diff --git a/addons/mass_mailing/wizard/mail_compose_message_view.xml b/addons/mass_mailing/wizard/mail_compose_message_view.xml
index f5dbf57a808..61cfe823006 100644
--- a/addons/mass_mailing/wizard/mail_compose_message_view.xml
+++ b/addons/mass_mailing/wizard/mail_compose_message_view.xml
@@ -9,7 +9,9 @@
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='notify']" position="after">
- <field name="mass_mailing_campaign_id"
+ <field name="mass_mailing_campaign_id" groups="mass_mailing.group_mass_mailing_campaign"
+ attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}"/>
+ <field name="mass_mailing_name"
attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}"/>
</xpath>
</field>
diff --git a/addons/mass_mailing/wizard/mail_mass_mailing_create_segment.py b/addons/mass_mailing/wizard/mail_mass_mailing_create_segment.py
deleted file mode 100644
index 0944e89f1de..00000000000
--- a/addons/mass_mailing/wizard/mail_mass_mailing_create_segment.py
+++ /dev/null
@@ -1,135 +0,0 @@
-# -*- 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 MailMassMailingCreate(osv.TransientModel):
- """Wizard to help creating mass mailing waves for a campaign. """
-
- _name = 'mail.mass_mailing.create'
- _description = 'Mass mailing creation'
-
- _columns = {
- 'mass_mailing_campaign_id': fields.many2one(
- 'mail.mass_mailing.campaign', 'Mass mailing campaign',
- required=True,
- ),
- 'model_id': fields.many2one(
- 'ir.model', 'Document Type',
- required=True,
- help='Document on which the mass mailing will run. This must be a '
- 'valid OpenERP model.',
- ),
- 'model_model': fields.related(
- 'model_id', 'name',
- type='char', string='Model Name'
- ),
- 'filter_id': fields.many2one(
- 'ir.filters', 'Filter',
- required=True,
- domain="[('model_id', '=', model_model)]",
- help='Filter to be applied on the document to find the records to be '
- 'mailed.',
- ),
- 'domain': fields.related(
- 'filter_id', 'domain',
- type='char', string='Domain',
- ),
- 'template_id': fields.many2one(
- 'email.template', 'Template', required=True,
- domain="[('model_id', '=', model_id)]",
- ),
- 'name': fields.char(
- 'Mailing Name', required=True,
- help='Name of the mass mailing.',
- ),
- 'mass_mailing_id': fields.many2one(
- 'mail.mass_mailing', 'Mass Mailing',
- ),
- }
-
- def _get_default_model_id(self, cr, uid, context=None):
- model_ids = self.pool['ir.model'].search(cr, uid, [('model', '=', 'res.partner')], context=context)
- return model_ids and model_ids[0] or False
-
- _defaults = {
- 'model_id': lambda self, cr, uid, ctx=None: self._get_default_model_id(cr, uid, context=ctx),
- }
-
- 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_mass_mailing(self, cr, uid, ids, context=None):
- """ Create a mass mailing based on wizard data, and update the wizard """
- for wizard in self.browse(cr, uid, ids, context=context):
- mass_mailing_values = {
- 'name': wizard.name,
- 'mass_mailing_campaign_id': wizard.mass_mailing_campaign_id.id,
- 'domain': wizard.domain,
- 'template_id': wizard.template_id.id,
- }
- mass_mailing_id = self.pool['mail.mass_mailing'].create(cr, uid, mass_mailing_values, context=context)
- self.write(cr, uid, [wizard.id], {'mass_mailing_id': mass_mailing_id}, context=context)
- return True
-
- def launch_composer(self, cr, uid, ids, context=None):
- """ Main wizard action: create a new mailing and launch the mail.compose.message
- email composer with wizard data. """
- self.create_mass_mailing(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_model': wizard.model_id.model,
- 'default_res_id': False,
- 'default_active_domain': wizard.domain,
- 'default_mass_mailing_campaign_id': wizard.mass_mailing_campaign_id.id,
- 'default_mass_mailing_id': wizard.mass_mailing_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,
- }
diff --git a/addons/mass_mailing/wizard/mail_mass_mailing_create_segment.xml b/addons/mass_mailing/wizard/mail_mass_mailing_create_segment.xml
deleted file mode 100644
index b2b48fb8618..00000000000
--- a/addons/mass_mailing/wizard/mail_mass_mailing_create_segment.xml
+++ /dev/null
@@ -1,82 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<openerp>
- <data>
-
- <!-- Wizard form view -->
- <record model="ir.ui.view" id="view_mail_mass_mailing_create_form">
- <field name="name">mail.mass_mailing.create.form</field>
- <field name="model">mail.mass_mailing.create</field>
- <field name="arch" type="xml">
- <form string="Create a Mass Mailing" version="7.0">
- <group>
- <field name="model_model" invisible="1"/>
- <field name="domain" invisible="1"/>
-
- <label for="mass_mailing_campaign_id"/>
- <div>
- <field name="mass_mailing_campaign_id"/>
- <p class="oe_grey"
- attrs="{'invisible': [('mass_mailing_campaign_id', '!=', False)]}">
- Please choose a mass mailing campaign that will hold the new mailing.
- </p>
- </div>
-
- <label for="model_id"/>
- <div>
- <field name="model_id"
- on_change="on_change_model_id(model_id, context)"/>
- <p class="oe_grey"
- attrs="{'invisible': [('model_id', '!=', False)]}">
- Please choose a model on which you will run the mass mailing.
- </p>
- </div>
-
- <label for="filter_id"/>
- <div>
- <field name="filter_id"
- on_change="on_change_filter_id(filter_id, context)"/>
- <p class="oe_grey"
- attrs="{'invisible': [('filter_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>
- </div>
-
- <label for="template_id"/>
- <div>
- <field name="template_id"/>
- <p class="oe_grey"
- attrs="{'invisible': [('template_id', '!=', False)]}">
- Please choose the template to use to render the emails
- to send.
- </p>
- </div>
-
- <label for="name"/>
- <div>
- <field name="name"/>
- <p class="oe_grey">
- Please choose the name of the mailing.
- </p>
- </div>
-
- <button name="launch_composer" type="object"
- string="Create mailing and launch email composer"/>
- </group>
- </form>
- </field>
- </record>
-
- <record model="ir.actions.act_window" id="action_mail_mass_mailing_create">
- <field name="name">Create Mass Mailing</field>
- <field name="res_model">mail.mass_mailing.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>
- <field name="context">{'default_mass_mailing_campaign_id': active_id}</field>
- </record>
-
- </data>
-</openerp>
diff --git a/addons/mass_mailing/wizard/test_mailing.py b/addons/mass_mailing/wizard/test_mailing.py
new file mode 100644
index 00000000000..bd1124a8cdc
--- /dev/null
+++ b/addons/mass_mailing/wizard/test_mailing.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+
+from openerp import tools
+from openerp.osv import osv, fields
+
+
+class TestMassMailing(osv.TransientModel):
+ _name = 'mail.mass_mailing.test'
+ _description = 'Sample Mail Wizard'
+
+ _columns = {
+ 'email_to': fields.char('Recipients', required=True,
+ help='Comma-separated list of email addresses.'),
+ 'mass_mailing_id': fields.many2one('mail.mass_mailing', 'Mailing', required=True),
+ }
+
+ _defaults = {
+ 'email_to': lambda self, cr, uid, ctx=None: self.pool['mail.message']._get_default_from(cr, uid, context=ctx),
+ }
+
+ def send_mail_test(self, cr, uid, ids, context=None):
+ Mail = self.pool['mail.mail']
+ for wizard in self.browse(cr, uid, ids, context=context):
+ mailing = wizard.mass_mailing_id
+ test_emails = tools.email_split(wizard.email_to)
+ mail_ids = []
+ for test_mail in test_emails:
+ mail_values = {
+ 'email_from': mailing.email_from,
+ 'reply_to': mailing.reply_to,
+ 'email_to': test_mail,
+ 'subject': mailing.name,
+ 'body_html': mailing.body_html,
+ 'auto_delete': True,
+ 'mailing_id': wizard.mass_mailing_id.id,
+ }
+ mail_ids.append(Mail.create(cr, uid, mail_values, context=context))
+ Mail.send(cr, uid, mail_ids, context=context)
+ self.pool['mail.mass_mailing'].write(cr, uid, [mailing.id], {'state': 'test'}, context=context)
+ return True
diff --git a/addons/mass_mailing/wizard/test_mailing.xml b/addons/mass_mailing/wizard/test_mailing.xml
new file mode 100644
index 00000000000..61ea8817bc4
--- /dev/null
+++ b/addons/mass_mailing/wizard/test_mailing.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<openerp>
+ <data>
+
+ <record model="ir.ui.view" id="view_mail_mass_mailing_test_form">
+ <field name="name">mail.mass_mailing.test.form</field>
+ <field name="model">mail.mass_mailing.test</field>
+ <field name="arch" type="xml">
+ <form string="Send a Sample Mail" version="7.0">
+ <p class="text-muted">
+ Send a sample of this mailing to the above of email addresses for test purpose.
+ </p>
+ <group>
+ <field name="email_to"/>
+ </group>
+ <footer>
+ <button string="Send Sample Mail" name="send_mail_test" type="object" class="oe_highlight"/>
+ or
+ <button string="Cancel" class="oe_link" special="cancel" />
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_mail_mass_mailing_test" model="ir.actions.act_window">
+ <field name="name">Mailing Test</field>
+ <field name="res_model">mail.mass_mailing.test</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
+ </data>
+</openerp>