diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 1fdfb9afd0d..b403dd75beb 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -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) diff --git a/addons/survey/wizard/survey_email_compose_message.py b/addons/survey/wizard/survey_email_compose_message.py index 404588194f4..ab1c00c0d37 100644 --- a/addons/survey/wizard/survey_email_compose_message.py +++ b/addons/survey/wizard/survey_email_compose_message.py @@ -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) diff --git a/addons/survey/wizard/survey_email_compose_message.xml b/addons/survey/wizard/survey_email_compose_message.xml index e6fe69bacd7..5b088b5f0d7 100644 --- a/addons/survey/wizard/survey_email_compose_message.xml +++ b/addons/survey/wizard/survey_email_compose_message.xml @@ -5,6 +5,7 @@ Survey - Send by Email + diff --git a/addons/survey_crm/__init__.py b/addons/survey_crm/__init__.py new file mode 100644 index 00000000000..e31f63c9bd2 --- /dev/null +++ b/addons/survey_crm/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# 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 survey diff --git a/addons/survey_crm/__openerp__.py b/addons/survey_crm/__openerp__.py new file mode 100644 index 00000000000..c647b87b01c --- /dev/null +++ b/addons/survey_crm/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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': '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: diff --git a/addons/survey_crm/crm_view.xml b/addons/survey_crm/crm_view.xml new file mode 100644 index 00000000000..3249bf8636e --- /dev/null +++ b/addons/survey_crm/crm_view.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/addons/survey_crm/survey.py b/addons/survey_crm/survey.py new file mode 100644 index 00000000000..6c7c22bcf11 --- /dev/null +++ b/addons/survey_crm/survey.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# 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 + + +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