~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to marketing/campaign/wizard/wizard_campaign_partner_add.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
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
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
import wizard
 
30
import pooler
 
31
 
 
32
campaign_form = '''<?xml version="1.0"?>
 
33
<form string="Add partners to campaign">
 
34
        <separator string="Default Values" colspan="4"/>
 
35
        <field name="campaign_step_id"/>
 
36
        <field name="priority"/>
 
37
        <field name="user_id"/>
 
38
        <newline/>
 
39
        <separator string="Partners" colspan="4"/>
 
40
        <field name="partners" nolabel="1" colspan="4"/>
 
41
</form>'''
 
42
 
 
43
campaign_fields = {
 
44
        'campaign_step_id': {'string':'First Campaign Step', 'type':'many2one', 'relation':'campaign.step', 'required':True},
 
45
        'priority': {'selection':[('0','Very Low'),('1','Low'),('2','Medium'),('3','Good'),('4','Very Good')], 'string':'Priority', 'type':'selection', 'required':True},
 
46
        'user_id': {'string':'User', 'type':'many2one', 'relation':'res.users'},
 
47
        'partners': {'string':'Partners', 'type':'many2many', 'required':True, 'relation':'res.partner'}
 
48
}
 
49
 
 
50
def _partner_add(self, cr, uid, data, context):
 
51
        partners = pooler.get_pool(cr.dbname).get('res.partner').browse(cr, uid, data['form']['partners'][0][2])
 
52
        campaign_partner_obj = pooler.get_pool(cr.dbname).get('campaign.partner')
 
53
        for partner in partners:
 
54
                if partner.address:
 
55
                        campaign_partner_obj.create(cr, uid, {
 
56
                                'name': partner.name,
 
57
                                'user_id': data['form']['user_id'],
 
58
                                'step': data['form']['campaign_step_id'],
 
59
                                'priority': data['form']['priority'],
 
60
                                'partner_id': partner.id,
 
61
                                'part_adr_id': partner.address and partner.address[0].id or False,
 
62
                                'contact': partner.address and partner.address[0].phone or False,
 
63
                                'campaign_id': data['id']
 
64
                        })
 
65
        return {}
 
66
 
 
67
class part_add(wizard.interface):
 
68
        states = {
 
69
                'init': {
 
70
                        'actions': [],
 
71
                        'result': {'type':'form', 'arch':campaign_form, 'fields':campaign_fields, 'state':[('end','Cancel'), ('add','Add these partners')]}
 
72
                },
 
73
                'add': {
 
74
                        'actions': [_partner_add],
 
75
                        'result': {'type':'state', 'state':'end'}
 
76
                }
 
77
        }
 
78
part_add('campaign.partner.add')
 
79