From 33fd9e01d6f50d7d6a3e379fd8544bb069a5d21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Aug 2013 15:03:34 +0200 Subject: [PATCH] [ADD] mass_mailing: added module for mass mailign campaigns. First draft of new module : simple mass mailing campaign model, linked to emails, compute some statistics mail.compose.message updated to the mass mailing campaigns in mass mail mode bzr revid: tde@openerp.com-20130807130334-nwd34fgsz4lc6lt1 --- addons/mass_mailing/__init__.py | 24 ++++++ addons/mass_mailing/__openerp__.py | 39 +++++++++ addons/mass_mailing/mail_mail.py | 35 ++++++++ addons/mass_mailing/mail_mail_view.xml | 18 ++++ addons/mass_mailing/mass_mailing.py | 84 +++++++++++++++++++ addons/mass_mailing/mass_mailing_view.xml | 48 +++++++++++ .../mass_mailing/security/ir.model.access.csv | 3 + addons/mass_mailing/wizard/__init__.py | 22 +++++ .../wizard/mail_compose_message.py | 51 +++++++++++ .../wizard/mail_compose_message_view.xml | 20 +++++ 10 files changed, 344 insertions(+) create mode 100644 addons/mass_mailing/__init__.py create mode 100644 addons/mass_mailing/__openerp__.py create mode 100644 addons/mass_mailing/mail_mail.py create mode 100644 addons/mass_mailing/mail_mail_view.xml create mode 100644 addons/mass_mailing/mass_mailing.py create mode 100644 addons/mass_mailing/mass_mailing_view.xml create mode 100644 addons/mass_mailing/security/ir.model.access.csv create mode 100644 addons/mass_mailing/wizard/__init__.py create mode 100644 addons/mass_mailing/wizard/mail_compose_message.py create mode 100644 addons/mass_mailing/wizard/mail_compose_message_view.xml diff --git a/addons/mass_mailing/__init__.py b/addons/mass_mailing/__init__.py new file mode 100644 index 00000000000..37f3850306a --- /dev/null +++ b/addons/mass_mailing/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-today OpenERP SA () +# +# 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 +# +############################################################################## + +import mass_mailing +import mail_mail +import wizard diff --git a/addons/mass_mailing/__openerp__.py b/addons/mass_mailing/__openerp__.py new file mode 100644 index 00000000000..e6fbb42e886 --- /dev/null +++ b/addons/mass_mailing/__openerp__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-today OpenERP SA () +# +# 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 +# +############################################################################## + +{ + 'name': 'Mass Mailing Campaigns', + 'version': '1.0', + 'author': 'OpenERP', + 'website': 'http://www.openerp.com', + 'category': 'Marketing', + 'depends': ['mail', 'email_template'], + 'description': """TODO""", + 'data': [ + 'mass_mailing_view.xml', + 'mail_mail_view.xml', + 'wizard/mail_compose_message_view.xml', + 'security/ir.model.access.csv', + ], + 'demo': [], + 'installable': True, + 'auto_install': False, +} diff --git a/addons/mass_mailing/mail_mail.py b/addons/mass_mailing/mail_mail.py new file mode 100644 index 00000000000..d7f46446b56 --- /dev/null +++ b/addons/mass_mailing/mail_mail.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-today OpenERP SA () +# +# 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 +# +############################################################################## + +from openerp.osv import osv, fields + + +class MailMail(osv.Model): + """Add the mass mailing campaign data to mail""" + _name = 'mail.mail' + _inherit = ['mail.mail'] + + _columns = { + 'mass_mailing_campaign_id': fields.many2one( + 'mail.mass_mailing.campaign', 'Mass Mailing Campaign', + ondelete='set null', + ), + } diff --git a/addons/mass_mailing/mail_mail_view.xml b/addons/mass_mailing/mail_mail_view.xml new file mode 100644 index 00000000000..dd66aede66f --- /dev/null +++ b/addons/mass_mailing/mail_mail_view.xml @@ -0,0 +1,18 @@ + + + + + + + mail.mail.form.mass_mailing + mail.mail + + + + + + + + + + diff --git a/addons/mass_mailing/mass_mailing.py b/addons/mass_mailing/mass_mailing.py new file mode 100644 index 00000000000..91392759b0e --- /dev/null +++ b/addons/mass_mailing/mass_mailing.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-today OpenERP SA () +# +# 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 +# +############################################################################## + +from openerp.osv import osv, fields + + +class MassMailingCampaign(osv.Model): + """Model of mass mailing campaigns. + """ + _name = "mail.mass_mailing.campaign" + _description = 'Mass Mailing Campaign' + + def _get_statistics(self, cr, uid, ids, name, arg, context=None): + """ Compute statistics of the mass mailing campaign """ + results = dict.fromkeys(ids, False) + for campaign in self.browse(cr, uid, ids, context=context): + if not campaign.mail_ids: + results[campaign.id] = { + 'sent': 0, + 'opened_ratio': 0.0, + 'replied_ratio': 0.0, + 'bounce_ratio': 0.0, + } + continue + results[campaign.id] = { + 'sent': len(campaign.mail_ids), + 'opened_ratio': len([mail for mail in campaign.mail_ids if mail.opened]) * 1.0 / len(campaign.mail_ids), + 'replied_ratio': len([mail for mail in campaign.mail_ids if mail.replied]) * 1.0 / len(campaign.mail_ids), + 'bounce_ratio': 0.0, + } + return results + + _columns = { + 'name': fields.char( + 'Campaign Name', required=True, + ), + 'template_id': fields.many2one( + 'email.template', 'Email Template', + ondelete='set null', + ), + 'mail_ids': fields.one2many( + 'mail.mail', 'mass_mailing_campaign_id', + 'Send Emails', + ), + # stat fields + 'sent': fields.function( + _get_statistics, + string='Sent Emails', + type='integer', multi='_get_statistics' + ), + 'opened_ratio': fields.function( + _get_statistics, + string='Opened Ratio', + type='float', multi='_get_statistics', + ), + 'replied_ratio': fields.function( + _get_statistics, + string='Replied Ratio', + type='float', multi='_get_statistics' + ), + 'bounce_ratio': fields.function( + _get_statistics, + string='Bounce Ratio', + type='float', multi='_get_statistics' + ), + } diff --git a/addons/mass_mailing/mass_mailing_view.xml b/addons/mass_mailing/mass_mailing_view.xml new file mode 100644 index 00000000000..bc28827343d --- /dev/null +++ b/addons/mass_mailing/mass_mailing_view.xml @@ -0,0 +1,48 @@ + + + + + + + mail.mass_mailing.campaign.tree + mail.mass_mailing.campaign + 10 + + + + + + + + + mail.mass_mailing.campaign.form + mail.mass_mailing.campaign + +
+ + + + + + + + + + +
+
+
+ + + Mass Mailing Campaigns + mail.mass_mailing.campaign + form + tree,form + + + + + +
+
diff --git a/addons/mass_mailing/security/ir.model.access.csv b/addons/mass_mailing/security/ir.model.access.csv new file mode 100644 index 00000000000..af6eaa7bb06 --- /dev/null +++ b/addons/mass_mailing/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_mass_mailing_campaign,mail.mass_mailing.campaign.template,model_mail_mass_mailing_campaign,,1,1,1,0 +access_mass_mailing_campaign_system,mail.mass_mailing.campaign.system,model_mail_mass_mailing_campaign,base.group_system,1,1,1,1 diff --git a/addons/mass_mailing/wizard/__init__.py b/addons/mass_mailing/wizard/__init__.py new file mode 100644 index 00000000000..155849362cd --- /dev/null +++ b/addons/mass_mailing/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-today OpenERP SA () +# +# 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 +# +############################################################################## + +import mail_compose_message diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py new file mode 100644 index 00000000000..2f74ef2c732 --- /dev/null +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-today OpenERP SA () +# +# 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 +# +############################################################################## + +from openerp.osv import osv, fields + + +class MailComposeMessage(osv.TransientModel): + """Add concept of mass mailing campaign to the mail.compose.message wizard + """ + _inherit = 'mail.compose.message' + + _columns = { + 'mass_mail_campaign_id': fields.many2one( + 'mail.mass_mailing.campaign', 'Mass mailing campaign' + ), + } + + def onchange_mass_mail_campaign_id(self, cr, uid, ids, mass_mail_campaign_id, context=None): + values = {} + if mass_mail_campaign_id: + campaign = self.pool['mail.mass_mailing.campaign'].browse(cr, uid, mass_mail_campaign_id, context=context) + if campaign and campaign.template_id: + values['template_id'] = campaign.template_id.id + return {'value': values} + + def render_message(self, cr, uid, wizard, res_id, context=None): + """ Override method that generated the mail content by adding the mass + mailing campaign, when doing pure email mass mailing. """ + res = super(MailComposeMessage, self).render_message(cr, uid, wizard, res_id, context=context) + print res, wizard.mass_mail_campaign_id + if wizard.composition_mode == 'mass_mail' and wizard.mass_mail_campaign_id: # TODO: which kind of mass mailing ? + res['mass_mailing_campaign_id'] = wizard.mass_mail_campaign_id.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 new file mode 100644 index 00000000000..bc5f1a9eb6a --- /dev/null +++ b/addons/mass_mailing/wizard/mail_compose_message_view.xml @@ -0,0 +1,20 @@ + + + + + + + mail.compose.message.form.mass_mailing + mail.compose.message + + + + + + + + + +