~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/addons/base/res/partner/wizard/wizard_spam.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id: wizard_spam.py 1005 2005-07-25 08:41:42Z nicoe $
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
import wizard
 
31
import pooler
 
32
import tools
 
33
 
 
34
email_send_form = '''<?xml version="1.0"?>
 
35
<form string="Mass Mailing">
 
36
        <field name="from"/>
 
37
        <newline/>
 
38
        <field name="subject"/>
 
39
        <newline/>
 
40
        <field name="text"/>
 
41
</form>'''
 
42
 
 
43
email_send_fields = {
 
44
        'from': {'string':"Sender's email", 'type':'char', 'size':64, 'required':True},
 
45
        'subject': {'string':'Subject', 'type':'char', 'size':64, 'required':True},
 
46
        'text': {'string':'Message', 'type':'text', 'required':True}
 
47
}
 
48
 
 
49
# this sends an email to ALL the addresses of the selected partners.
 
50
def _mass_mail_send(self, cr, uid, data, context):
 
51
        nbr = 0
 
52
        partners = pooler.get_pool(cr.dbname).get('res.partner').browse(cr, uid, data['ids'], context)
 
53
        for partner in partners:
 
54
                for adr in partner.address:
 
55
                        if adr.email:
 
56
                                name = adr.name or partner.name
 
57
                                to = '%s <%s>' % (name, adr.email)
 
58
#TODO: add some tests to check for invalid email addresses
 
59
#CHECKME: maybe we should use res.partner/email_send
 
60
                                tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'])
 
61
                                nbr += 1
 
62
                pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
 
63
                                {'name': 'Email sent through mass mailing',
 
64
                                 'partner_id': partner.id,
 
65
                                 'description': data['form']['text'], })
 
66
#TODO: log number of message sent
 
67
        return {'email_sent': nbr}
 
68
 
 
69
class part_email(wizard.interface):
 
70
        states = {
 
71
                'init': {
 
72
                        'actions': [],
 
73
                        'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel'), ('send','Send Email')]}
 
74
                },
 
75
                'send': {
 
76
                        'actions': [_mass_mail_send],
 
77
                        'result': {'type': 'state', 'state':'end'}
 
78
                }
 
79
        }
 
80
part_email('res.partner.spam_send')