1 ##############################################################################
3 # Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 # Fabien Pinckaers <fp@tiny.Be>
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
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.
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.
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.
27 ##############################################################################
35 view_form_profit = """<?xml version="1.0"?>
37 <image name="gtk-dialog-info"/>
39 <separator string="Select a profile" colspan="2"/>
41 <field align="0.0" name="profile"/>
43 <label string="A profile sets a pre-selection of modules for enterprise needs." colspan="2" align="0.0"/>
45 <label string="You'll be able to install others modules later through the Administration menu." colspan="2" align="0.0"/>
49 view_form_charts = """<?xml version="1.0"?>
51 <image name="gtk-dialog-info" colspan="2"/>
53 <separator string="Select a chart of accounts" colspan="2"/>
55 <field name="charts" align="0.0"/>
57 <label string="There are many other chart of accounts available." colspan="2" align="0.0"/>
59 <label string="If you don't select one now, you'll be able to install an other one through the Administration menu." colspan="2" align="0.0"/>
63 view_form_company = """<?xml version="1.0"?>
65 <image name="gtk-dialog-info" colspan="2"/>
67 <separator string="Define main company" colspan="4"/>
69 <field name="name" align="0.0" colspan="4" required="True"/>
71 <field name="street" align="0.0"/>
72 <field name="street2" align="0.0"/>
73 <field name="zip" align="0.0"/>
74 <field name="city" align="0.0"/>
75 <field name="country_id" align="0.0"/>
76 <field name="state_id" align="0.0"/>
77 <field name="email" align="0.0"/>
78 <field name="phone" align="0.0"/>
79 <field name="currency" align="0.0"/>
80 <separator string="Report header" colspan="4"/>
82 <field name="rml_header1" align="0.0" colspan="4"/>
83 <field name="rml_footer1" align="0.0" colspan="4"/>
84 <field name="rml_footer2" align="0.0" colspan="4"/>
88 view_form_update = """<?xml version="1.0"?>
90 <image name="gtk-dialog-info" colspan="2"/>
92 <separator string="Summary" colspan="2"/>
94 <field name="profile" align="0.0" readonly="1"/>
96 <field name="charts" align="0.0" readonly="1"/>
98 <field name="name" align="0.0" readonly="1"/>
103 view_form_finish = """<?xml version="1.0"?>
104 <form string="Setup">
105 <image name="gtk-dialog-info" colspan="2"/>
106 <group colspan="2" col="4">
107 <separator colspan="4" string="Installation done"/>
108 <label align="0.0" colspan="4" string="Your new database is now fully installed."/>
109 <label align="0.0" colspan="4" string="You can start using the system or continue the configuration using the menu Administration\Configuration"/>
114 class wizard_base_setup(wizard.interface):
116 def _get_profiles(self, cr, uid, context):
117 module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
118 ids=module_obj.search(cr, uid, [('category_id', '=', 'Profile'),
119 ('state', '<>', 'uninstallable')])
120 res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
121 res.append((-1, 'Minimal Profile'))
125 def _get_charts(self, cr, uid, context):
126 module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
127 ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'),
128 ('state', '<>', 'uninstallable')])
129 res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
130 res.append((-1, 'None'))
131 res.sort(lambda x,y: cmp(x[1],y[1]))
134 def _get_company(self, cr, uid, data, context):
135 pool=pooler.get_pool(cr.dbname)
136 company_obj=pool.get('res.company')
137 ids=company_obj.search(cr, uid, [])
140 company=company_obj.browse(cr, uid, ids)[0]
141 self.fields['name']['default']=company.name
142 self.fields['currency']['default']=company.currency_id.id
144 #self.fields['rml_header1']['default']=company.rml_header1
145 #self.fields['rml_footer1']['default']=company.rml_footer1
146 #self.fields['rml_footer2']['default']=company.rml_footer2
147 #if not company.partner_id.address:
149 #address=company.partner_id.address[0]
150 #self.fields['street']['default']=address.street
151 #self.fields['street2']['default']=address.street2
152 #self.fields['zip']['default']=address.zip
153 #self.fields['city']['default']=address.city
154 #self.fields['email']['default']=address.email
155 #self.fields['phone']['default']=address.phone
156 #if address.state_id:
157 # self.fields['state_id']['default']=address.state_id.id
159 # self.fields['state_id']['default']=-1
160 #if address.country_id:
161 # self.fields['country_id']['default']=address.country_id.id
163 # self.fields['country_id']['default']=-1
166 def _get_states(self, cr, uid, context):
167 pool=pooler.get_pool(cr.dbname)
168 state_obj=pool.get('res.country.state')
169 ids=state_obj.search(cr, uid, [])
170 res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids)]
172 res.sort(lambda x,y: cmp(x[1],y[1]))
175 def _get_countries(self, cr, uid, context):
176 pool=pooler.get_pool(cr.dbname)
177 country_obj=pool.get('res.country')
178 ids=country_obj.search(cr, uid, [])
179 res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids)]
180 res.sort(lambda x,y: cmp(x[1],y[1]))
183 def _update(self, cr, uid, data, context):
184 pool=pooler.get_pool(cr.dbname)
186 if 'profile' in data['form'] and data['form']['profile'] > 0:
187 module_obj=pool.get('ir.module.module')
188 module_obj.state_change(cr, uid, [data['form']['profile']], 'to install', context)
189 if 'charts' in data['form'] and data['form']['charts'] > 0:
190 module_obj=pool.get('ir.module.module')
191 module_obj.state_change(cr, uid, [data['form']['charts']], 'to install', context)
193 company_obj=pool.get('res.company')
194 partner_obj=pool.get('res.partner')
195 address_obj=pool.get('res.partner.address')
196 ids=company_obj.search(cr, uid, [])
197 company=company_obj.browse(cr, uid, ids)[0]
198 company_obj.write(cr, uid, [company.id], {
199 'name': form['name'],
200 'rml_header1': form['rml_header1'],
201 'rml_footer1': form['rml_footer1'],
202 'rml_footer2': form['rml_footer2'],
203 'currency_id': form['currency'],
205 partner_obj.write(cr, uid, [company.partner_id.id], {
206 'name': form['name'],
209 'name': form['name'],
210 'street': form['street'],
211 'street2': form['street2'],
213 'city': form['city'],
214 'email': form['email'],
215 'phone': form['phone'],
216 'country_id': form['country_id'],
218 if form['state_id'] > 0:
219 values['state_id']=form['state_id']
220 if company.partner_id.address:
221 address=company.partner_id.address[0]
222 address_obj.write(cr, uid, [address.id], values)
224 values['partner_id']=company.partner_id.id
225 add_id=address_obj.create(cr, uid, values)
228 (db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
230 lang_obj=pool.get('res.lang')
231 lang_ids=lang_obj.search(cr, uid, [])
232 langs=lang_obj.browse(cr, uid, lang_ids)
234 if lang.code and lang.code != 'en_US':
235 filename=os.path.join(tools.config["root_path"], "i18n", lang.code + ".csv")
236 tools.trans_load(cr.dbname, filename, lang.code)
239 def _menu(self, cr, uid, data, context):
240 users_obj=pooler.get_pool(cr.dbname).get('res.users')
241 action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
243 ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
244 menu=action_obj.browse(cr, uid, ids)[0]
246 ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
247 users_obj.write(cr, uid, ids, {'action_id': menu.id})
248 ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
249 users_obj.write(cr, uid, ids, {'menu_id': menu.id})
254 'view_id': (menu.view_id and\
255 (menu.view_id.id, menu.view_id.name)) or False,
256 'domain': menu.domain,
257 'res_model': menu.res_model,
258 'src_model': menu.src_model,
259 'view_type': menu.view_type,
260 'view_mode': menu.view_mode,
264 def _next(self, cr, uid, data, context):
265 if not data['form']['profile'] or data['form']['profile'] <= 0:
269 def _previous(self, cr, uid, data, context):
270 if 'profile' not in data['form'] or data['form']['profile'] <= 0:
278 'selection':_get_profiles,
283 'string':'Chart of accounts',
285 'selection':_get_charts,
290 'string': 'Company Name',
305 'string': 'Zip code',
317 'selection':_get_states,
322 'selection':_get_countries,
335 'string': 'Currency',
337 'relation': 'res.currency',
341 'string': 'Report Header',
346 'string': 'Report Footer 1',
351 'string': 'Report Footer 2',
358 'actions': [_get_company],
359 'result': {'type': 'form', 'arch': view_form_profit, 'fields': fields,
361 ('menu', 'Cancel', 'gtk-cancel'),
362 ('next', 'Next', 'gtk-go-forward', True)
368 'result': {'type': 'choice', 'next_state': _next}
372 'result': {'type': 'form', 'arch': view_form_charts, 'fields': fields,
374 ('init', 'Previous', 'gtk-go-back'),
375 ('company', 'Next', 'gtk-go-forward', True)
381 'result': {'type': 'form', 'arch': view_form_company, 'fields': fields,
383 ('previous', 'Previous', 'gtk-go-back'),
384 ('update', 'Next', 'gtk-go-forward', True)
390 'result': {'type': 'choice', 'next_state': _previous}
394 'result': {'type': 'form', 'arch': view_form_update, 'fields': fields,
396 ('company', 'Previous', 'gtk-go-back'),
397 ('finish', 'Install', 'gtk-ok', True)
402 'actions': [_update],
403 'result': {'type': 'form', 'arch': view_form_finish, 'fields': {},
405 ('menu', 'Ok', 'gtk-ok', True)
411 'result': {'type': 'action', 'action': _menu, 'state': 'end'}
415 wizard_base_setup('base_setup.base_setup')