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-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-info" size="64" colspan="2"/>
53 <separator string="Select a chart of accounts" colspan="2"/>
55 <field name="charts" align="0.0"/>
57 <label string="(If you don't select a chart of accounts, you'll need to set up one manually)." colspan="2" align="0.0"/>
61 view_form_company = """<?xml version="1.0"?>
63 <image name="gtk-info" size="64" colspan="2"/>
65 <separator string="Define main company" colspan="4"/>
67 <field name="name" align="0.0" colspan="4" required="True"/>
69 <field name="street" align="0.0"/>
70 <field name="street2" align="0.0"/>
71 <field name="zip" align="0.0"/>
72 <field name="city" align="0.0"/>
73 <field name="country_id" align="0.0"/>
74 <field name="state_id" align="0.0"/>
75 <field name="email" align="0.0"/>
76 <field name="phone" align="0.0"/>
77 <separator string="Report header" colspan="4"/>
79 <field name="rml_header1" align="0.0" colspan="4"/>
80 <field name="rml_footer1" align="0.0" colspan="4"/>
81 <field name="rml_footer2" align="0.0" colspan="4"/>
85 view_form_update = """<?xml version="1.0"?>
87 <image name="gtk-info" size="64" colspan="2"/>
89 <separator string="Summary" colspan="2"/>
91 <field name="profile" align="0.0" readonly="1"/>
93 <field name="charts" align="0.0" readonly="1"/>
95 <field name="name" align="0.0" readonly="1"/>
100 view_form_finish = """<?xml version="1.0"?>
101 <form string="Setup">
102 <image name="gtk-info" size="64" colspan="2"/>
103 <group colspan="2" col="4">
104 <separator colspan="4" string="Installation done"/>
105 <label align="0.0" colspan="4" string="Your new database is now fully installed."/>
106 <label align="0.0" colspan="4" string="You can start using the system or continue the configuration using the menu Administration\Configuration"/>
111 class wizard_base_setup(wizard.interface):
112 def _get_profiles(self, cr, uid, context):
113 module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
114 ids=module_obj.search(cr, uid, [('category_id', '=', 'Profile'), ('state', '<>', 'installed')])
115 res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
116 res.append((-1, 'Minimal Profile'))
119 def _get_charts(self, cr, uid, context):
120 module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
121 ids=module_obj.search(cr, uid, [('category_id', '=', 'Account charts'), ('state', '<>', 'installed')])
122 res=[(m.id, m.shortdesc) for m in module_obj.browse(cr, uid, ids)]
123 res.append((-1, 'None'))
124 res.sort(lambda x,y: cmp(x[1],y[1]))
126 def _get_company(self, cr, uid, data, context):
127 pool=pooler.get_pool(cr.dbname)
128 company_obj=pool.get('res.company')
129 ids=company_obj.search(cr, uid, [])
132 company=company_obj.browse(cr, uid, ids)[0]
133 self.fields['name']['default']=company.name
135 #self.fields['rml_header1']['default']=company.rml_header1
136 #self.fields['rml_footer1']['default']=company.rml_footer1
137 #self.fields['rml_footer2']['default']=company.rml_footer2
138 #if not company.partner_id.address:
140 #address=company.partner_id.address[0]
141 #self.fields['street']['default']=address.street
142 #self.fields['street2']['default']=address.street2
143 #self.fields['zip']['default']=address.zip
144 #self.fields['city']['default']=address.city
145 #self.fields['email']['default']=address.email
146 #self.fields['phone']['default']=address.phone
147 #if address.state_id:
148 # self.fields['state_id']['default']=address.state_id.id
150 # self.fields['state_id']['default']=-1
151 #if address.country_id:
152 # self.fields['country_id']['default']=address.country_id.id
154 # self.fields['country_id']['default']=-1
156 def _get_states(self, cr, uid, context):
157 pool=pooler.get_pool(cr.dbname)
158 state_obj=pool.get('res.country.state')
159 ids=state_obj.search(cr, uid, [])
160 res=[(state.id, state.name) for state in state_obj.browse(cr, uid, ids)]
162 res.sort(lambda x,y: cmp(x[1],y[1]))
164 def _get_countries(self, cr, uid, context):
165 pool=pooler.get_pool(cr.dbname)
166 country_obj=pool.get('res.country')
167 ids=country_obj.search(cr, uid, [])
168 res=[(country.id, country.name) for country in country_obj.browse(cr, uid, ids)]
169 res.sort(lambda x,y: cmp(x[1],y[1]))
171 def _update(self, cr, uid, data, context):
172 pool=pooler.get_pool(cr.dbname)
174 if 'profile' in data['form'] and data['form']['profile'] > 0:
175 module_obj=pool.get('ir.module.module')
176 module_obj.state_change(cr, uid, [data['form']['profile']], 'to install', context)
177 if 'charts' in data['form'] and data['form']['charts'] > 0:
178 module_obj=pool.get('ir.module.module')
179 module_obj.state_change(cr, uid, [data['form']['charts']], 'to install', context)
181 company_obj=pool.get('res.company')
182 partner_obj=pool.get('res.partner')
183 address_obj=pool.get('res.partner.address')
184 ids=company_obj.search(cr, uid, [])
185 company=company_obj.browse(cr, uid, ids)[0]
186 company_obj.write(cr, uid, [company.id], {
187 'name': form['name'],
188 'rml_header1': form['rml_header1'],
189 'rml_footer1': form['rml_footer1'],
190 'rml_footer2': form['rml_footer2'],
192 partner_obj.write(cr, uid, [company.partner_id.id], {
193 'name': form['name'],
196 'name': form['name'],
197 'street': form['street'],
198 'street2': form['street2'],
200 'city': form['city'],
201 'email': form['email'],
202 'phone': form['phone'],
203 'country_id': form['country_id']
205 if form['state_id'] > 0:
206 values['state_id']=form['state_id']
207 if company.partner_id.address:
208 address=company.partner_id.address[0]
209 address_obj.write(cr, uid, [address.id], values)
211 values['partner_id']=company.partner_id.id
212 add_id=address_obj.create(cr, uid, values)
215 (db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
217 lang_obj=pool.get('res.lang')
218 lang_ids=lang_obj.search(cr, uid, [])
219 langs=lang_obj.browse(cr, uid, lang_ids)
221 if lang.code and lang.code != 'en_US':
222 filename=os.path.join(tools.config["root_path"], "i18n", lang.code + ".csv")
223 tools.trans_load(cr.dbname, filename, lang.code)
225 def _menu(self, cr, uid, data, context):
226 users_obj=pooler.get_pool(cr.dbname).get('res.users')
227 actions_obj=pooler.get_pool(cr.dbname).get('ir.actions.act_window')
229 ids=actions_obj.search(cr, uid, [('name', '=', 'Menu')])
230 menu=actions_obj.browse(cr, uid, ids)[0]
232 ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
233 users_obj.write(cr, uid, ids, {'action_id': menu.id})
236 'type':'ir.actions.act_window',
237 'res_model':'ir.ui.menu',
239 'domain': "[('parent_id','=',False)]",
240 'view_id': (menu.view_id.id, menu.view_id.name),
242 def _next(self, cr, uid, data, context):
243 if not data['form']['profile'] or data['form']['profile'] <= 0:
246 def _previous(self, cr, uid, data, context):
247 if 'profile' not in data['form'] or data['form']['profile'] <= 0:
254 'selection':_get_profiles,
259 'string':'Chart of accounts',
261 'selection':_get_charts,
266 'string': 'Company Name',
281 'string': 'Zip code',
293 'selection':_get_states,
298 'selection':_get_countries,
311 'string': 'Report Header',
316 'string': 'Report Footer 1',
321 'string': 'Report Footer 2',
328 'actions':[_get_company],
329 'result':{'type':'form', 'arch':view_form_profit, 'fields':fields, 'state':[('menu', 'Cancel', 'gtk-cancel'), ('next', 'Next', 'gtk-go-forward')]}
333 'result':{'type':'choice', 'next_state': _next}
337 'result':{'type':'form', 'arch':view_form_charts, 'fields':fields, 'state':[('init', 'Previous', 'gtk-go-back'), ('company', 'Next', 'gtk-go-forward')]}
341 'result':{'type':'form', 'arch':view_form_company, 'fields':fields, 'state':[('previous', 'Previous', 'gtk-go-back'), ('update', 'Next', 'gtk-go-forward')]}
345 'result':{'type':'choice', 'next_state': _previous}
349 'result':{'type':'form', 'arch':view_form_update, 'fields':fields, 'state':[('company', 'Previous', 'gtk-go-back'), ('finish', 'Install', 'gtk-ok')]}
353 'result':{'type':'form', 'arch':view_form_finish, 'fields':{}, 'state':[('menu', 'Ok', 'gtk-ok')]}
357 'result':{'type':'action', 'action':_menu, 'state':'end'}
360 wizard_base_setup('base_setup.base_setup')