~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to base_setup/wizard/wizard_base_setup.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) 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
import time
 
32
import tools
 
33
 
 
34
view_form_profit = """<?xml version="1.0"?>
 
35
<form string="Setup">
 
36
        <image name="gtk-info"/>
 
37
        <group>
 
38
                <separator string="Select a profile" colspan="2"/>
 
39
                <newline/>
 
40
                <field align="0.0" name="profile"/>
 
41
                <newline/>
 
42
                <label string="A profile sets a pre-selection of modules for enterprise needs." colspan="2" align="0.0"/>
 
43
                <newline/>
 
44
                <label string="You'll be able to install others modules later through the Administration menu." colspan="2" align="0.0"/>
 
45
        </group>
 
46
</form>"""
 
47
 
 
48
view_form_charts = """<?xml version="1.0"?>
 
49
<form string="Setup">
 
50
        <image name="gtk-info" size="64" colspan="2"/>
 
51
        <group>
 
52
                <separator string="Select a chart of accounts" colspan="2"/>
 
53
                <newline/>
 
54
                <field name="charts" align="0.0"/>
 
55
                <newline/>
 
56
                <label string="(If you don't select a chart of accounts, you'll need to set up one manually)." colspan="2" align="0.0"/>
 
57
        </group>
 
58
</form>"""
 
59
 
 
60
view_form_company = """<?xml version="1.0"?>
 
61
<form string="Setup">
 
62
        <image name="gtk-info" size="64" colspan="2"/>
 
63
        <group>
 
64
                <separator string="Define main company" colspan="4"/>
 
65
                <newline/>
 
66
                <field name="name" align="0.0" colspan="3" required="True"/>
 
67
                <newline/>
 
68
                <field name="street" align="0.0"/>
 
69
                <field name="street2" align="0.0"/>
 
70
                <field name="zip" align="0.0"/>
 
71
                <field name="city" align="0.0"/>
 
72
                <field name="country_id" align="0.0"/>
 
73
                <field name="state_id" align="0.0"/>
 
74
                <field name="email" align="0.0"/>
 
75
                <field name="phone" align="0.0"/>
 
76
                <separator string="Report header" colspan="4"/>
 
77
                <newline/>
 
78
                <field name="rml_header1" align="0.0" colspan="3"/>
 
79
                <field name="rml_footer1" align="0.0" colspan="3"/>
 
80
                <field name="rml_footer2" align="0.0" colspan="3"/>
 
81
        </group>
 
82
</form>"""
 
83
 
 
84
view_form_update = """<?xml version="1.0"?>
 
85
<form string="Setup">
 
86
        <image name="gtk-info" size="64" colspan="2"/>
 
87
        <group>
 
88
                <separator string="Summary" colspan="2"/>
 
89
                <newline/>
 
90
                <field name="profile" align="0.0" readonly="1"/>
 
91
                <newline/>
 
92
                <field name="charts" align="0.0" readonly="1"/>
 
93
                <newline/>
 
94
                <field name="name" align="0.0" readonly="1"/>
 
95
        </group>
 
96
</form>
 
97
"""
 
98
 
 
99
view_form_finish = """<?xml version="1.0"?>
 
100
<form string="Setup">
 
101
        <image name="gtk-info" size="64" colspan="2"/>
 
102
        <group colspan="2" col="4">
 
103
                <separator colspan="4" string="Installation done"/>
 
104
                <label align="0.0" colspan="4" string="Your new database is now fully installed."/>
 
105
                <label align="0.0" colspan="4" string="You can start using the system or continue the configuration using the menu Administration\Configuration"/>
 
106
        </group>
 
107
</form>
 
108
"""
 
109
 
 
110
class wizard_base_setup(wizard.interface):
 
111
        def _get_profiles(self, cr, uid, context):
 
112
                module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
 
113
                ids=module_obj.search(cr, uid, [('category_id', '=', 'Profile'), ('state', '<>', 'installed')])
 
114
                res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
 
115
                res.append((-1, 'Minimal Profile'))
 
116
                res.sort()
 
117
                return res
 
118
        def _get_charts(self, cr, uid, context):
 
119
                module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
 
120
                ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'), ('state', '<>', 'installed')])
 
121
                res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
 
122
                res.append((-1, 'None'))
 
123
                res.sort(lambda x,y: cmp(x[1],y[1]))
 
124
                return res
 
125
        def _get_company(self, cr, uid, data, context):
 
126
                pool=pooler.get_pool(cr.dbname)
 
127
                company_obj=pool.get('res.company')
 
128
                ids=company_obj.search(cr, uid, [])
 
129
                if not ids:
 
130
                        return {}
 
131
                company=company_obj.browse(cr, uid, ids)[0]
 
132
                self.fields['name']['default']=company.name
 
133
                return {}
 
134
                #self.fields['rml_header1']['default']=company.rml_header1
 
135
                #self.fields['rml_footer1']['default']=company.rml_footer1
 
136
                #self.fields['rml_footer2']['default']=company.rml_footer2
 
137
                #if not company.partner_id.address:
 
138
                #       return {}
 
139
                #address=company.partner_id.address[0]
 
140
                #self.fields['street']['default']=address.street
 
141
                #self.fields['street2']['default']=address.street2
 
142
                #self.fields['zip']['default']=address.zip
 
143
                #self.fields['city']['default']=address.city
 
144
                #self.fields['email']['default']=address.email
 
145
                #self.fields['phone']['default']=address.phone
 
146
                #if address.state_id:
 
147
                #       self.fields['state_id']['default']=address.state_id.id
 
148
                #else:
 
149
                #       self.fields['state_id']['default']=-1
 
150
                #if address.country_id:
 
151
                #       self.fields['country_id']['default']=address.country_id.id
 
152
                #else:
 
153
                #       self.fields['country_id']['default']=-1
 
154
                #return {}
 
155
        def _get_states(self, cr, uid, context):
 
156
                pool=pooler.get_pool(cr.dbname)
 
157
                state_obj=pool.get('res.country.state')
 
158
                ids=state_obj.search(cr, uid, [])
 
159
                res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids)]
 
160
                res.append((-1, ''))
 
161
                res.sort(lambda x,y: cmp(x[1],y[1]))
 
162
                return res
 
163
        def _get_countries(self, cr, uid, context):
 
164
                pool=pooler.get_pool(cr.dbname)
 
165
                country_obj=pool.get('res.country')
 
166
                ids=country_obj.search(cr, uid, [])
 
167
                res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids)]
 
168
                res.sort(lambda x,y: cmp(x[1],y[1]))
 
169
                return res
 
170
        def _update(self, cr, uid, data, context):
 
171
                pool=pooler.get_pool(cr.dbname)
 
172
                form=data['form']
 
173
                if 'profile' in data['form'] and data['form']['profile'] > 0:
 
174
                        module_obj=pool.get('ir.module.module')
 
175
                        module_obj.state_change(cr, uid, [data['form']['profile']], 'to install', context)
 
176
                if 'charts' in data['form'] and data['form']['charts'] > 0:
 
177
                        module_obj=pool.get('ir.module.module')
 
178
                        module_obj.state_change(cr, uid, [data['form']['charts']], 'to install', context)
 
179
 
 
180
                company_obj=pool.get('res.company')
 
181
                partner_obj=pool.get('res.partner')
 
182
                address_obj=pool.get('res.partner.address')
 
183
                ids=company_obj.search(cr, uid, [])
 
184
                company=company_obj.browse(cr, uid, ids)[0]
 
185
                company_obj.write(cr, uid, [company.id], {
 
186
                                'name': form['name'],
 
187
                                'rml_header1': form['rml_header1'],
 
188
                                'rml_footer1': form['rml_footer1'],
 
189
                                'rml_footer2': form['rml_footer2'],
 
190
                        })
 
191
                partner_obj.write(cr, uid, [company.partner_id.id], {
 
192
                                'name': form['name'],
 
193
                        })
 
194
                values={
 
195
                                        'name': form['name'],
 
196
                                        'street': form['street'],
 
197
                                        'street2': form['street2'],
 
198
                                        'zip': form['zip'],
 
199
                                        'city': form['city'],
 
200
                                        'email': form['email'],
 
201
                                        'phone': form['phone'],
 
202
                                        'country_id': form['country_id']
 
203
                                }
 
204
                if form['state_id'] > 0:
 
205
                        values['state_id']=form['state_id']
 
206
                if company.partner_id.address:
 
207
                        address=company.partner_id.address[0]
 
208
                        address_obj.write(cr, uid, [address.id], values)
 
209
                else:
 
210
                        values['partner_id']=company.partner_id.id
 
211
                        add_id=address_obj.create(cr, uid, values)
 
212
 
 
213
                cr.commit()
 
214
                (db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
 
215
 
 
216
                lang_obj=pool.get('res.lang')
 
217
                lang_ids=lang_obj.search(cr, uid, [])
 
218
                langs=lang_obj.browse(cr, uid, lang_ids)
 
219
                for lang in langs:
 
220
                        if lang.code and lang.code != 'en_EN':
 
221
                                filename=tools.config["root_path"]+"/i18n/" + lang.code + ".csv"
 
222
                                tools.trans_load(cr.dbname, filename, lang.code)
 
223
                return {}
 
224
        def _menu(self, cr, uid, data, context):
 
225
                users_obj=pooler.get_pool(cr.dbname).get('res.users')
 
226
                actions_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
 
227
                
 
228
                ids=actions_obj.search(cr, uid, [('name', '=', 'Menu')])
 
229
                menu=actions_obj.browse(cr, uid, ids)[0]
 
230
 
 
231
                ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
 
232
                users_obj.write(cr, uid, ids, {'action_id': menu.id})
 
233
                return {
 
234
                        'name': 'Menu',
 
235
                        'type':'ir.actions.act_window',
 
236
                        'res_model':'ir.ui.menu',
 
237
                        'view_type':'tree',
 
238
                        'domain': "[('parent_id','=',False)]",
 
239
                        'view_id': (menu.view_id.id, menu.view_id.name),
 
240
                }
 
241
        def _next(self, cr, uid, data, context):
 
242
                if not data['form']['profile'] or data['form']['profile'] <= 0:
 
243
                        return 'company'
 
244
                return 'charts'
 
245
        def _previous(self, cr, uid, data, context):
 
246
                if 'profile' not in data['form'] or data['form']['profile'] <= 0:
 
247
                        return 'init'
 
248
                return 'charts'
 
249
        fields={
 
250
                'profile':{
 
251
                        'string':'Profile',
 
252
                        'type':'selection',
 
253
                        'selection':_get_profiles,
 
254
                        'default': -1,
 
255
                        'required': True,
 
256
                },
 
257
                'charts':{
 
258
                        'string':'Chart of accounts',
 
259
                        'type':'selection',
 
260
                        'selection':_get_charts,
 
261
                        'default': -1,
 
262
                        'required': True,
 
263
                },
 
264
                'name':{
 
265
                        'string': 'Company Name',
 
266
                        'type': 'char',
 
267
                        'size': 64,
 
268
                },
 
269
                'street':{
 
270
                        'string': 'Street',
 
271
                        'type': 'char',
 
272
                        'size': 128,
 
273
                },
 
274
                'street2':{
 
275
                        'string': 'Street2',
 
276
                        'type': 'char',
 
277
                        'size': 128,
 
278
                },
 
279
                'zip':{
 
280
                        'string': 'Zip',
 
281
                        'type': 'char',
 
282
                        'size': 24,
 
283
                },
 
284
                'city':{
 
285
                        'string': 'City',
 
286
                        'type': 'char',
 
287
                        'size': 128,
 
288
                },
 
289
                'state_id':{
 
290
                        'string': 'State',
 
291
                        'type': 'selection',
 
292
                        'selection':_get_states,
 
293
                },
 
294
                'country_id':{
 
295
                        'string': 'Country',
 
296
                        'type': 'selection',
 
297
                        'selection':_get_countries,
 
298
                },
 
299
                'email':{
 
300
                        'string': 'E-mail',
 
301
                        'type': 'char',
 
302
                        'size': 64,
 
303
                },
 
304
                'phone':{
 
305
                        'string': 'Phone',
 
306
                        'type': 'char',
 
307
                        'size': 64,
 
308
                },
 
309
                'rml_header1':{
 
310
                        'string': 'Report Header',
 
311
                        'type': 'char',
 
312
                        'size': 200,
 
313
                },
 
314
                'rml_footer1':{
 
315
                        'string': 'Report Footer 1',
 
316
                        'type': 'char',
 
317
                        'size': 200,
 
318
                },
 
319
                'rml_footer2':{
 
320
                        'string': 'Report Footer 2',
 
321
                        'type': 'char',
 
322
                        'size': 200,
 
323
                },
 
324
        }
 
325
        states={
 
326
                'init':{
 
327
                        'actions':[_get_company],
 
328
                        'result':{'type':'form', 'arch':view_form_profit, 'fields':fields, 'state':[('menu', 'Cancel', 'gtk-cancel'), ('next', 'Next', 'gtk-go-forward')]}
 
329
                },
 
330
                'next': {
 
331
                        'actions':[],
 
332
                        'result':{'type':'choice', 'next_state': _next}
 
333
                },
 
334
                'charts':{
 
335
                        'actions':[],
 
336
                        'result':{'type':'form', 'arch':view_form_charts, 'fields':fields, 'state':[('init', 'Previous', 'gtk-go-back'), ('company', 'Next', 'gtk-go-forward')]}
 
337
                },
 
338
                'company':{
 
339
                        'actions':[],
 
340
                        'result':{'type':'form', 'arch':view_form_company, 'fields':fields, 'state':[('previous', 'Previous', 'gtk-go-back'), ('update', 'Next', 'gtk-go-forward')]}
 
341
                },
 
342
                'previous':{
 
343
                        'actions':[],
 
344
                        'result':{'type':'choice', 'next_state': _previous}
 
345
                },
 
346
                'update':{
 
347
                        'actions':[],
 
348
                        'result':{'type':'form', 'arch':view_form_update, 'fields':fields, 'state':[('company', 'Previous', 'gtk-go-back'), ('finish', 'Install', 'gtk-ok')]}
 
349
                },
 
350
                'finish':{
 
351
                        'actions':[_update],
 
352
                        'result':{'type':'form', 'arch':view_form_finish, 'fields':{}, 'state':[('menu', 'Ok', 'gtk-ok')]}
 
353
                },
 
354
                'menu': {
 
355
                        'actions':[],
 
356
                        'result':{'type':'action', 'action':_menu, 'state':'end'}
 
357
                }
 
358
        }
 
359
wizard_base_setup('base_setup.base_setup')