[IMP] survey_crm: add a survey mass mailing option on crm.lead

bzr revid: chm@openerp.com-20130429113244-pvoam5mxo82wfinj
This commit is contained in:
Christophe Matthieu
2013-04-29 13:32:44 +02:00
parent 0883de2a2a
commit cc67ae177e
7 changed files with 138 additions and 16 deletions
-4
View File
@@ -50,10 +50,6 @@ class survey(osv.osv):
else:
return []
def default_get(self, cr, uid, fields, context=None):
data = super(survey, self).default_get(cr, uid, fields, context)
return data
def _get_tot_start_survey(self, cr, uid, ids, name, arg, context=None):
""" Compute if the message is unread by the current user. """
res = dict((id, 0) for id in ids)
@@ -68,30 +68,31 @@ class survey_mail_compose_message(osv.TransientModel):
'date_deadline': fields.date(string="Deadline to which the invitation to respond is valid", help="Deadline to which the invitation to respond for this survey is valid. If the field is empty, the invitation is still valid."),
}
def get_default_partner_ids(self, cr, uid, context=None):
res = []
if context is None:
context = {}
if context.get('active_model') == 'res.partner' and context.get('active_ids'):
res = context.get('active_ids')
return res
_defaults = {
'public': 'email_private',
'survey_id': lambda self,cr,uid,ctx={}: ctx.get('model') == 'survey' and ctx.get('res_id') or None,
'partner_ids': get_default_partner_ids,
}
def default_get(self, cr, uid, fields, context=None):
res = super(survey_mail_compose_message, self).default_get(cr, uid, fields, context=context)
if context.get('active_model') == 'res.partner' and context.get('active_ids'):
res.update({'partner_ids': context.get('active_ids')})
return res
def onchange_multi_email(self, cr, uid, ids, multi_email, context=None):
emails = list(set(emails_split.split(multi_email or "")))
emails_checked = []
error_message = ""
for email in emails:
email = email.strip()
if email:
if not re.search(r"^[^@]+@[^@]+$", email):
raise osv.except_osv(_('Warning!'), _("An email address is incorrect: '%s'" % email))
error_message += "\n'%s'" % email
else:
emails_checked.append(email)
if error_message:
raise osv.except_osv(_('Warning!'), _("One email at least is incorrect: %s" % error_message))
emails_checked.sort()
values = {'multi_email': '\n'.join(emails_checked)}
return {'value': values}
@@ -192,7 +193,7 @@ class survey_mail_compose_message(osv.TransientModel):
emails = list(set(emails_split.split(wizard.multi_email)) - set([partner.email for partner in wizard.partner_ids]))
for email in emails:
email = email.strip()
if email:
if re.search(r"^[^@]+@[^@]+$", email):
emails_list.append(email)
# remove public anonymous access
@@ -204,7 +205,7 @@ class survey_mail_compose_message(osv.TransientModel):
if not len(emails_list) and not len(partner_list):
if wizard.model == 'res.partner' and wizard.res_id:
return False
raise osv.except_osv(_('Warning!'), _("Please enter at least one recipient."))
raise osv.except_osv(_('Warning!'), _("Please enter at least one valid recipient."))
for email in emails_list:
partner_id = partner_obj.search(cr, uid, [('email', '=', email)], context=context)
@@ -5,6 +5,7 @@
<!--Survey send invitation Email template -->
<record id="email_template_survey" model="email.template">
<field name="name">Survey - Send by Email</field>
<field name="model_id" ref="model_survey"/>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); ">
+22
View File
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<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 survey
+41
View File
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
{
'name': 'Survey CRM',
'version': '0.1',
'category': 'Tools',
'complexity': 'easy',
'description': """
This module adds a survey mass mailing button inside the more option of lead view
=================================================================================
""",
'author': 'OpenERP SA',
'depends': ['crm', 'survey'],
'data': [
'crm_view.xml',
],
'installable': True,
'auto_install': True,
'category': 'Hidden',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Replace the default mass-mailing wizard in base with the composition wizard -->
<act_window name="Partner Survey Mailing"
res_model="survey.mail.compose.message"
src_model="crm.lead"
view_mode="form"
multi="True"
target="new"
key2="client_action_multi"
id="survey.action_partner_survey_mail_crm"
context="{
'default_use_template': True,
'default_template_id': ref('survey.email_template_survey'),
}"/>
</data>
</openerp>
+43
View File
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<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
class survey_mail_compose_message(osv.TransientModel):
_inherit = 'survey.mail.compose.message'
def default_get(self, cr, uid, fields, context=None):
res = super(survey_mail_compose_message, self).default_get(cr, uid, fields, context=context)
if context.get('active_model') == 'crm.lead' and context.get('active_ids'):
partner_ids = []
emails_list = []
for lead in self.pool.get('crm.lead').browse(cr, uid, context.get('active_ids'), context=context):
if lead.partner_id:
partner_ids.append(lead.partner_id.id)
else:
email = lead.contact_name and "%s <%s>" % (lead.contact_name, lead.email_from or "") or lead.email_from or None
if email and email not in emails_list:
emails_list.append(email)
multi_email = "\n".join(emails_list)
res.update({'partner_ids': list(set(partner_ids)), 'multi_email': multi_email})
return res