~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to dm/wizard/campaign_group.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-12 06:43:12 UTC
  • Revision ID: fp@tinyerp.com-20081112064312-fp85io97i1e95tuz
moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
import wizard
 
23
import pooler
 
24
 
 
25
class wizard_campaign_group(wizard.interface):
 
26
 
 
27
    new_group = '''<?xml version="1.0"?>
 
28
    <form string="Select Group">
 
29
        <field name="group" colspan="4"/>
 
30
    </form>'''
 
31
    
 
32
    group_form = '''<?xml version="1.0"?>
 
33
    <form string="Create Group">
 
34
        <field name="group" colspan="4"/>
 
35
    </form>'''
 
36
    
 
37
    message ='''<?xml version="1.0"?>
 
38
    <form string="Create Group">
 
39
        <label align="0.0" colspan="4" string="Selected campaign has been added in the group.Campaigns that are already in some group will not be added in new group and will remain in same group"/>
 
40
    </form>'''
 
41
    
 
42
    error_message = '''<?xml version="1.0"?>
 
43
    <form string="Error!!!">
 
44
        <label align="0.0" colspan="4" string="Group name can't be none.You have to select any avilable group or create new"/>
 
45
    </form>'''
 
46
    
 
47
    def _add_group(self, cr, uid, data, context):
 
48
        if context.has_key('group_id'):
 
49
            group_id = context['group_id']
 
50
        else :
 
51
            group_id = data['form']['group']
 
52
        pool=pooler.get_pool(cr.dbname)
 
53
        grp_ids = pool.get('dm.campaign.group').browse(cr, uid, group_id)
 
54
        camp_obj = pool.get('dm.campaign')
 
55
        for r in camp_obj.browse(cr,uid,data['ids']):
 
56
            if not grp_ids.campaign_ids:
 
57
                if not r.campaign_group_id:
 
58
                        camp_obj.write(cr,uid,[r.id],{'campaign_group_id':group_id})
 
59
            else:
 
60
                for c in grp_ids.campaign_ids:
 
61
                    if c.offer_id.id == r.offer_id.id:
 
62
                        if not r.campaign_group_id:
 
63
                            camp_obj.write(cr,uid,[r.id],{'campaign_group_id':group_id})
 
64
                    else:
 
65
                        raise wizard.except_wizard('Error !', 'Offer should be same for all the campaigns in a group : %s !' %c.offer_id.name)
 
66
 
 
67
        return {}
 
68
 
 
69
    def _new_group(self, cr, uid, data, context):
 
70
        pool=pooler.get_pool(cr.dbname)
 
71
        group_id = pool.get('dm.campaign.group').create(cr,uid,{'name':data['form']['group']})
 
72
        context['group_id'] = group_id
 
73
        self._add_group(cr,uid,data,context)
 
74
        return {}
 
75
    
 
76
    def _get_groups(self, cr, uid, context):
 
77
        pool=pooler.get_pool(cr.dbname)
 
78
        group_obj=pool.get('dm.campaign.group')
 
79
        ids=group_obj.search(cr, uid, [])
 
80
        res=[(group.id, group.name) for group in group_obj.browse(cr, uid, ids)]
 
81
        res.sort(lambda x,y: cmp(x[1],y[1]))
 
82
        return res    
 
83
    
 
84
    def _next(self, cr, uid, data, context):
 
85
        if not data['form']['group']:
 
86
            return 'error'
 
87
        return 'add'
 
88
 
 
89
    
 
90
    group_fields = {
 
91
                    
 
92
        'group': {'string': 'Select Group', 'type': 'selection', 'selection':_get_groups, }
 
93
        
 
94
        }
 
95
    
 
96
    new_group_fields = {
 
97
        'group': {'string': 'Group Name', 'type': 'char', 'size':64, 'required':True }
 
98
        }    
 
99
    
 
100
    states = {
 
101
        'init': {
 
102
            'actions': [],
 
103
            'result': {'type':'form', 'arch':group_form, 'fields':group_fields, 'state':[('end','Cancel'),('name_group','Create New Group'),('next','Add in Group'),]}
 
104
            },
 
105
        'name_group': {
 
106
            'actions': [],
 
107
            'result': {'type':'form', 'arch':new_group, 'fields':new_group_fields, 'state':[('end','Cancel'),('new','Create Group')]}
 
108
            },            
 
109
        'new': {
 
110
            'actions': [_new_group],
 
111
            'result': {'type': 'form', 'arch': message, 'fields':{} ,'state': [('end', 'Ok', 'gtk-ok', True)]}
 
112
        },
 
113
        'next': {
 
114
            'actions': [],
 
115
            'result': {'type': 'choice', 'next_state': _next}
 
116
        },
 
117
        'error': {
 
118
            'actions': [],
 
119
            'result': {'type': 'form', 'arch': error_message, 'fields':{} ,'state': [('end','Cancel'),('init','Select the group')]}
 
120
        },        
 
121
        'add': {
 
122
            'actions': [_add_group],
 
123
            'result': {'type': 'form', 'arch': message, 'fields':{} ,'state': [('end', 'Ok', 'gtk-ok', True)]}
 
124
        },
 
125
        }
 
126
wizard_campaign_group("wizard_campaign_group")
 
127
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'