1 ##############################################################################
3 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
36 view_form_profit = """<?xml version="1.0"?>
38 <image name="gtk-dialog-info"/>
40 <separator string="Select a profile" colspan="2"/>
42 <field align="0.0" name="profile"/>
44 <label string="A profile sets a pre-selection of modules for enterprise needs." colspan="2" align="0.0"/>
46 <label string="You'll be able to install others modules later through the Administration menu." colspan="2" align="0.0"/>
50 view_form_charts = """<?xml version="1.0"?>
52 <image name="gtk-dialog-info" colspan="2"/>
54 <separator string="Select a chart of accounts" colspan="2"/>
56 <field name="charts" align="0.0"/>
58 <label string="There are many other chart of accounts available on the OpenERP website." colspan="2" align="0.0"/>
60 <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"/>
64 view_form_company = """<?xml version="1.0"?>
66 <image name="gtk-dialog-info" colspan="2"/>
68 <separator string="Define main company" colspan="4"/>
70 <field name="name" align="0.0" colspan="4" required="True"/>
72 <field name="street" align="0.0"/>
73 <field name="street2" align="0.0"/>
74 <field name="zip" align="0.0"/>
75 <field name="city" align="0.0"/>
76 <field name="country_id" align="0.0"/>
77 <field name="state_id" align="0.0"/>
78 <field name="email" align="0.0"/>
79 <field name="phone" align="0.0"/>
80 <field name="currency" align="0.0"/>
81 <separator string="Report header" colspan="4"/>
83 <field name="rml_header1" align="0.0" colspan="4"/>
84 <field name="rml_footer1" align="0.0" colspan="4"/>
85 <field name="rml_footer2" align="0.0" colspan="4"/>
89 view_form_update = """<?xml version="1.0"?>
91 <image name="gtk-dialog-info" colspan="2"/>
93 <separator string="Summary" colspan="2"/>
95 <field name="profile" align="0.0" readonly="1"/>
97 <field name="charts" align="0.0" readonly="1"/>
99 <field name="name" align="0.0" readonly="1"/>
104 view_form_finish = """<?xml version="1.0"?>
105 <form string="Setup">
106 <image name="gtk-dialog-info" colspan="2"/>
107 <group colspan="2" col="4">
108 <separator colspan="4" string="Installation Done"/>
109 <label align="0.0" colspan="4" string="Your new database is now fully installed."/>
110 <label align="0.0" colspan="4" string="You can start configuring the system or connect directly to the database using the default setup."/>
115 class wizard_base_setup(wizard.interface):
117 def _get_profiles(self, cr, uid, context):
118 module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
119 ids=module_obj.search(cr, uid, [('category_id', '=', 'Profile'),
120 ('state', '<>', 'uninstallable')])
121 res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
122 res.append((-1, 'Minimal Profile'))
126 def _get_charts(self, cr, uid, context):
127 module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
128 ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'),
129 ('state', '<>', 'uninstallable')])
130 res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
131 res.append((-1, 'None'))
132 res.sort(lambda x,y: cmp(x[1],y[1]))
135 def _get_company(self, cr, uid, data, context):
136 pool=pooler.get_pool(cr.dbname)
137 company_obj=pool.get('res.company')
138 ids=company_obj.search(cr, uid, [])
141 company=company_obj.browse(cr, uid, ids)[0]
142 self.fields['name']['default']=company.name
143 self.fields['currency']['default']=company.currency_id.id
145 #self.fields['rml_header1']['default']=company.rml_header1
146 #self.fields['rml_footer1']['default']=company.rml_footer1
147 #self.fields['rml_footer2']['default']=company.rml_footer2
148 #if not company.partner_id.address:
150 #address=company.partner_id.address[0]
151 #self.fields['street']['default']=address.street
152 #self.fields['street2']['default']=address.street2
153 #self.fields['zip']['default']=address.zip
154 #self.fields['city']['default']=address.city
155 #self.fields['email']['default']=address.email
156 #self.fields['phone']['default']=address.phone
157 #if address.state_id:
158 # self.fields['state_id']['default']=address.state_id.id
160 # self.fields['state_id']['default']=-1
161 #if address.country_id:
162 # self.fields['country_id']['default']=address.country_id.id
164 # self.fields['country_id']['default']=-1
167 def _get_states(self, cr, uid, context):
168 pool=pooler.get_pool(cr.dbname)
169 state_obj=pool.get('res.country.state')
170 ids=state_obj.search(cr, uid, [])
171 res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids)]
173 res.sort(lambda x,y: cmp(x[1],y[1]))
176 def _get_countries(self, cr, uid, context):
177 pool=pooler.get_pool(cr.dbname)
178 country_obj=pool.get('res.country')
179 ids=country_obj.search(cr, uid, [])
180 res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids)]
181 res.sort(lambda x,y: cmp(x[1],y[1]))
184 def _update(self, cr, uid, data, context):
185 pool=pooler.get_pool(cr.dbname)
187 if 'profile' in data['form'] and data['form']['profile'] > 0:
188 module_obj=pool.get('ir.module.module')
189 module_obj.state_change(cr, uid, [data['form']['profile']], 'to install', context)
190 if 'charts' in data['form'] and data['form']['charts'] > 0:
191 module_obj=pool.get('ir.module.module')
192 module_obj.state_change(cr, uid, [data['form']['charts']], 'to install', context)
194 company_obj=pool.get('res.company')
195 partner_obj=pool.get('res.partner')
196 address_obj=pool.get('res.partner.address')
197 ids=company_obj.search(cr, uid, [])
198 company=company_obj.browse(cr, uid, ids)[0]
199 company_obj.write(cr, uid, [company.id], {
200 'name': form['name'],
201 'rml_header1': form['rml_header1'],
202 'rml_footer1': form['rml_footer1'],
203 'rml_footer2': form['rml_footer2'],
204 'currency_id': form['currency'],
206 partner_obj.write(cr, uid, [company.partner_id.id], {
207 'name': form['name'],
210 'name': form['name'],
211 'street': form['street'],
212 'street2': form['street2'],
214 'city': form['city'],
215 'email': form['email'],
216 'phone': form['phone'],
217 'country_id': form['country_id'],
219 if form['state_id'] > 0:
220 values['state_id']=form['state_id']
221 if company.partner_id.address:
222 address=company.partner_id.address[0]
223 address_obj.write(cr, uid, [address.id], values)
225 values['partner_id']=company.partner_id.id
226 add_id=address_obj.create(cr, uid, values)
229 (db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
231 lang_obj=pool.get('res.lang')
232 lang_ids=lang_obj.search(cr, uid, [])
233 langs=lang_obj.browse(cr, uid, lang_ids)
235 if lang.code and lang.code != 'en_US':
236 filename=os.path.join(tools.config["root_path"], "i18n", lang.code + ".csv")
237 tools.trans_load(cr.dbname, filename, lang.code)
240 def _menu(self, cr, uid, data, context):
241 users_obj=pooler.get_pool(cr.dbname).get('res.users')
242 action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
244 ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
245 menu=action_obj.browse(cr, uid, ids)[0]
247 ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
248 users_obj.write(cr, uid, ids, {'action_id': menu.id})
249 ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
250 users_obj.write(cr, uid, ids, {'menu_id': menu.id})
255 'view_id': (menu.view_id and\
256 (menu.view_id.id, menu.view_id.name)) or False,
257 'domain': menu.domain,
258 'res_model': menu.res_model,
259 'src_model': menu.src_model,
260 'view_type': menu.view_type,
261 'view_mode': menu.view_mode,
265 def _next(self, cr, uid, data, context):
266 if not data['form']['profile'] or data['form']['profile'] <= 0:
270 def _previous(self, cr, uid, data, context):
271 if 'profile' not in data['form'] or data['form']['profile'] <= 0:
275 def _config(self, cr, uid, data, context=None):
276 users_obj=pooler.get_pool(cr.dbname).get('res.users')
277 action_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
279 ids=action_obj.search(cr, uid, [('name', '=', 'Menu')])
280 menu=action_obj.browse(cr, uid, ids)[0]
282 ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
283 users_obj.write(cr, uid, ids, {'action_id': menu.id})
284 ids=users_obj.search(cr, uid, [('menu_id', '=', 'Setup')])
285 users_obj.write(cr, uid, ids, {'menu_id': menu.id})
289 'res_model': 'ir.module.module.configuration.wizard',
290 'type': 'ir.actions.act_window',
298 'selection':_get_profiles,
303 'string':'Chart of accounts',
305 'selection':_get_charts,
310 'string': 'Company Name',
325 'string': 'Zip code',
337 'selection':_get_states,
342 'selection':_get_countries,
355 'string': 'Currency',
357 'relation': 'res.currency',
361 'string': 'Report Header',
363 'help': """This sentence will appear at the top right corner of your reports.
364 We suggest you to put a slogan here:
365 "Open Source Business Solutions".""",
369 'string': 'Report Footer 1',
371 'help': """This sentence will appear at the bottom of your reports.
372 We suggest you to write legal sentences here:
373 Web: http://openerp.com - Fax: +32.81.73.35.01 - Fortis Bank: 126-2013269-07""",
377 'string': 'Report Footer 2',
378 'help': """This sentence will appear at the bottom of your reports.
379 We suggest you to put bank information here:
380 IBAN: BE74 1262 0121 6907 - SWIFT: CPDF BE71 - VAT: BE0477.472.701""",
387 'actions': [_get_company],
388 'result': {'type': 'form', 'arch': view_form_profit, 'fields': fields,
390 ('menu', 'Cancel', 'gtk-cancel'),
391 ('next', 'Next', 'gtk-go-forward', True)
397 'result': {'type': 'choice', 'next_state': _next}
401 'result': {'type': 'form', 'arch': view_form_charts, 'fields': fields,
403 ('init', 'Previous', 'gtk-go-back'),
404 ('company', 'Next', 'gtk-go-forward', True)
410 'result': {'type': 'form', 'arch': view_form_company, 'fields': fields,
412 ('previous', 'Previous', 'gtk-go-back'),
413 ('update', 'Next', 'gtk-go-forward', True)
419 'result': {'type': 'choice', 'next_state': _previous}
423 'result': {'type': 'form', 'arch': view_form_update, 'fields': fields,
425 ('company', 'Previous', 'gtk-go-back'),
426 ('finish', 'Install', 'gtk-ok', True)
431 'actions': [_update],
432 'result': {'type': 'form', 'arch': view_form_finish, 'fields': {},
434 ('menu', 'Use Directly'),
435 ('config', 'Start Configuration', 'gtk-ok', True)
448 'result': {'type': 'action', 'action': _menu, 'state': 'end'}
452 wizard_base_setup('base_setup.base_setup')