CLIENT,SERVER: improve language
[odoo/odoo.git] / addons / base_setup / wizard / wizard_base_setup.py
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 import os
34
35 view_form_profit = """<?xml version="1.0"?>
36 <form string="Setup">
37         <image name="gtk-info"/>
38         <group>
39                 <separator string="Select a profile" colspan="2"/>
40                 <newline/>
41                 <field align="0.0" name="profile"/>
42                 <newline/>
43                 <label string="A profile sets a pre-selection of modules for enterprise needs." colspan="2" align="0.0"/>
44                 <newline/>
45                 <label string="You'll be able to install others modules later through the Administration menu." colspan="2" align="0.0"/>
46         </group>
47 </form>"""
48
49 view_form_charts = """<?xml version="1.0"?>
50 <form string="Setup">
51         <image name="gtk-info" size="64" colspan="2"/>
52         <group>
53                 <separator string="Select a chart of accounts" colspan="2"/>
54                 <newline/>
55                 <field name="charts" align="0.0"/>
56                 <newline/>
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"/>
58         </group>
59 </form>"""
60
61 view_form_company = """<?xml version="1.0"?>
62 <form string="Setup">
63         <image name="gtk-info" size="64" colspan="2"/>
64         <group>
65                 <separator string="Define main company" colspan="4"/>
66                 <newline/>
67                 <field name="name" align="0.0" colspan="4" required="True"/>
68                 <newline/>
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"/>
78                 <newline/>
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"/>
82         </group>
83 </form>"""
84
85 view_form_update = """<?xml version="1.0"?>
86 <form string="Setup">
87         <image name="gtk-info" size="64" colspan="2"/>
88         <group>
89                 <separator string="Summary" colspan="2"/>
90                 <newline/>
91                 <field name="profile" align="0.0" readonly="1"/>
92                 <newline/>
93                 <field name="charts" align="0.0" readonly="1"/>
94                 <newline/>
95                 <field name="name" align="0.0" readonly="1"/>
96         </group>
97 </form>
98 """
99
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"/>
107         </group>
108 </form>
109 """
110
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'))
117                 res.sort()
118                 return res
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]))
125                 return res
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, [])
130                 if not ids:
131                         return {}
132                 company=company_obj.browse(cr, uid, ids)[0]
133                 self.fields['name']['default']=company.name
134                 return {}
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:
139                 #       return {}
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
149                 #else:
150                 #       self.fields['state_id']['default']=-1
151                 #if address.country_id:
152                 #       self.fields['country_id']['default']=address.country_id.id
153                 #else:
154                 #       self.fields['country_id']['default']=-1
155                 #return {}
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)]
161                 res.append((-1, ''))
162                 res.sort(lambda x,y: cmp(x[1],y[1]))
163                 return res
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]))
170                 return res
171         def _update(self, cr, uid, data, context):
172                 pool=pooler.get_pool(cr.dbname)
173                 form=data['form']
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)
180
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'],
191                         })
192                 partner_obj.write(cr, uid, [company.partner_id.id], {
193                                 'name': form['name'],
194                         })
195                 values={
196                                         'name': form['name'],
197                                         'street': form['street'],
198                                         'street2': form['street2'],
199                                         'zip': form['zip'],
200                                         'city': form['city'],
201                                         'email': form['email'],
202                                         'phone': form['phone'],
203                                         'country_id': form['country_id']
204                                 }
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)
210                 else:
211                         values['partner_id']=company.partner_id.id
212                         add_id=address_obj.create(cr, uid, values)
213
214                 cr.commit()
215                 (db, pool)=pooler.restart_pool(cr.dbname, update_module=True)
216
217                 lang_obj=pool.get('res.lang')
218                 lang_ids=lang_obj.search(cr, uid, [])
219                 langs=lang_obj.browse(cr, uid, lang_ids)
220                 for lang in langs:
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)
224                 return {}
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')
228                 
229                 ids=actions_obj.search(cr, uid, [('name', '=', 'Menu')])
230                 menu=actions_obj.browse(cr, uid, ids)[0]
231
232                 ids=users_obj.search(cr, uid, [('action_id', '=', 'Setup')])
233                 users_obj.write(cr, uid, ids, {'action_id': menu.id})
234                 return {
235                         'name': 'Menu',
236                         'type':'ir.actions.act_window',
237                         'res_model':'ir.ui.menu',
238                         'view_type':'tree',
239                         'domain': "[('parent_id','=',False)]",
240                         'view_id': (menu.view_id.id, menu.view_id.name),
241                 }
242         def _next(self, cr, uid, data, context):
243                 if not data['form']['profile'] or data['form']['profile'] <= 0:
244                         return 'company'
245                 return 'charts'
246         def _previous(self, cr, uid, data, context):
247                 if 'profile' not in data['form'] or data['form']['profile'] <= 0:
248                         return 'init'
249                 return 'charts'
250         fields={
251                 'profile':{
252                         'string':'Profile',
253                         'type':'selection',
254                         'selection':_get_profiles,
255                         'default': -1,
256                         'required': True,
257                 },
258                 'charts':{
259                         'string':'Chart of accounts',
260                         'type':'selection',
261                         'selection':_get_charts,
262                         'default': -1,
263                         'required': True,
264                 },
265                 'name':{
266                         'string': 'Company Name',
267                         'type': 'char',
268                         'size': 64,
269                 },
270                 'street':{
271                         'string': 'Street',
272                         'type': 'char',
273                         'size': 128,
274                 },
275                 'street2':{
276                         'string': 'Street2',
277                         'type': 'char',
278                         'size': 128,
279                 },
280                 'zip':{
281                         'string': 'Zip code',
282                         'type': 'char',
283                         'size': 24,
284                 },
285                 'city':{
286                         'string': 'City',
287                         'type': 'char',
288                         'size': 128,
289                 },
290                 'state_id':{
291                         'string': 'State',
292                         'type': 'selection',
293                         'selection':_get_states,
294                 },
295                 'country_id':{
296                         'string': 'Country',
297                         'type': 'selection',
298                         'selection':_get_countries,
299                 },
300                 'email':{
301                         'string': 'E-mail',
302                         'type': 'char',
303                         'size': 64,
304                 },
305                 'phone':{
306                         'string': 'Phone',
307                         'type': 'char',
308                         'size': 64,
309                 },
310                 'rml_header1':{
311                         'string': 'Report Header',
312                         'type': 'char',
313                         'size': 200,
314                 },
315                 'rml_footer1':{
316                         'string': 'Report Footer 1',
317                         'type': 'char',
318                         'size': 200,
319                 },
320                 'rml_footer2':{
321                         'string': 'Report Footer 2',
322                         'type': 'char',
323                         'size': 200,
324                 },
325         }
326         states={
327                 'init':{
328                         'actions':[_get_company],
329                         'result':{'type':'form', 'arch':view_form_profit, 'fields':fields, 'state':[('menu', 'Cancel', 'gtk-cancel'), ('next', 'Next', 'gtk-go-forward')]}
330                 },
331                 'next': {
332                         'actions':[],
333                         'result':{'type':'choice', 'next_state': _next}
334                 },
335                 'charts':{
336                         'actions':[],
337                         'result':{'type':'form', 'arch':view_form_charts, 'fields':fields, 'state':[('init', 'Previous', 'gtk-go-back'), ('company', 'Next', 'gtk-go-forward')]}
338                 },
339                 'company':{
340                         'actions':[],
341                         'result':{'type':'form', 'arch':view_form_company, 'fields':fields, 'state':[('previous', 'Previous', 'gtk-go-back'), ('update', 'Next', 'gtk-go-forward')]}
342                 },
343                 'previous':{
344                         'actions':[],
345                         'result':{'type':'choice', 'next_state': _previous}
346                 },
347                 'update':{
348                         'actions':[],
349                         'result':{'type':'form', 'arch':view_form_update, 'fields':fields, 'state':[('company', 'Previous', 'gtk-go-back'), ('finish', 'Install', 'gtk-ok')]}
350                 },
351                 'finish':{
352                         'actions':[_update],
353                         'result':{'type':'form', 'arch':view_form_finish, 'fields':{}, 'state':[('menu', 'Ok', 'gtk-ok')]}
354                 },
355                 'menu': {
356                         'actions':[],
357                         'result':{'type':'action', 'action':_menu, 'state':'end'}
358                 }
359         }
360 wizard_base_setup('base_setup.base_setup')