1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21
##############################################################################
25
class wizard_campaign_group(wizard.interface):
27
new_group = '''<?xml version="1.0"?>
28
<form string="Select Group">
29
<field name="group" colspan="4"/>
32
group_form = '''<?xml version="1.0"?>
33
<form string="Create Group">
34
<field name="group" colspan="4"/>
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"/>
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"/>
47
def _add_group(self, cr, uid, data, context):
48
if context.has_key('group_id'):
49
group_id = context['group_id']
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})
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})
65
raise wizard.except_wizard('Error !', 'Offer should be same for all the campaigns in a group : %s !' %c.offer_id.name)
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)
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]))
84
def _next(self, cr, uid, data, context):
85
if not data['form']['group']:
92
'group': {'string': 'Select Group', 'type': 'selection', 'selection':_get_groups, }
97
'group': {'string': 'Group Name', 'type': 'char', 'size':64, 'required':True }
103
'result': {'type':'form', 'arch':group_form, 'fields':group_fields, 'state':[('end','Cancel'),('name_group','Create New Group'),('next','Add in Group'),]}
107
'result': {'type':'form', 'arch':new_group, 'fields':new_group_fields, 'state':[('end','Cancel'),('new','Create Group')]}
110
'actions': [_new_group],
111
'result': {'type': 'form', 'arch': message, 'fields':{} ,'state': [('end', 'Ok', 'gtk-ok', True)]}
115
'result': {'type': 'choice', 'next_state': _next}
119
'result': {'type': 'form', 'arch': error_message, 'fields':{} ,'state': [('end','Cancel'),('init','Select the group')]}
122
'actions': [_add_group],
123
'result': {'type': 'form', 'arch': message, 'fields':{} ,'state': [('end', 'Ok', 'gtk-ok', True)]}
126
wizard_campaign_group("wizard_campaign_group")
127
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'