[IMP]: base_setup: in the main config wizard: we should have as before, if a module...
[odoo/odoo.git] / addons / base_setup / installer.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21 from osv import fields, osv
22 import pooler
23 import pytz
24
25 class base_setup_installer(osv.osv_memory):
26     _name = 'base.setup.installer'
27     _inherit = 'res.config.installer'
28
29     _install_if = {
30         ('sale','crm'): ['sale_crm'],
31         ('sale','project'): ['project_mrp'],
32     }
33     _columns = {
34         # Generic modules
35         'crm':fields.boolean('Customer Relationship Management',
36             help="Helps you track and manage relations with customers such as"
37                  " leads, requests or issues. Can automatically send "
38                  "reminders, escalate requests or trigger business-specific "
39                  "actions based on standard events."),
40         'sale':fields.boolean('Sales Management',
41             help="Helps you handle your quotations, sale orders and invoicing"
42                  "."),
43         'project':fields.boolean('Project Management',
44             help="Helps you manage your projects and tasks by tracking them, "
45                  "generating plannings, etc..."),
46         'knowledge':fields.boolean('Knowledge Management',
47             help="Lets you install addons geared towards sharing knowledge "
48                  "with and between your employees."),
49         'stock':fields.boolean('Warehouse Management',
50             help="Helps you manage your inventory and main stock operations: delivery orders, receptions, etc."),
51         'mrp':fields.boolean('Manufacturing',
52             help="Helps you manage your manufacturing processes and generate "
53                  "reports on those processes."),
54         'account_voucher':fields.boolean('Invoicing',
55             help="Allows you to create your invoices and track the payments. It is an easier version of the accounting module for managers who are not accountants."),
56         'account_accountant':fields.boolean('Accounting & Finance',
57             help="Helps you handle your accounting needs, if you are not an accountant, we suggest you to install only the Invoicing "),
58         'purchase':fields.boolean('Purchase Management',
59             help="Helps you manage your purchase-related processes such as "
60                  "requests for quotations, supplier invoices, etc..."),
61         'hr':fields.boolean('Human Resources',
62             help="Helps you manage your human resources by encoding your employees structure, generating work sheets, tracking attendance and more."),
63         'point_of_sale':fields.boolean('Point of Sales',
64             help="Helps you get the most out of your points of sales with "
65                  "fast sale encoding, simplified payment mode encoding, "
66                  "automatic picking lists generation and more."),
67         'marketing':fields.boolean('Marketing',
68             help="Helps you manage your marketing campaigns step by step."),
69         'profile_tools':fields.boolean('Extra Tools',
70             help="Lets you install various interesting but non-essential tools "
71                 "like Survey, Lunch and Ideas box."),
72         'report_designer':fields.boolean('Advanced Reporting',
73             help="Lets you install various tools to simplify and enhance "
74                  "OpenERP's report creation."),
75         # Vertical modules
76         'product_expiry':fields.boolean('Food Industry',
77             help="Installs a preselected set of OpenERP applications "
78                 "which will help you manage your industry."),
79         'association':fields.boolean('Associations',
80             help="Installs a preselected set of OpenERP "
81                  "applications which will help you manage your association "
82                  "more efficiently."),
83         'auction':fields.boolean('Auction Houses',
84             help="Installs a preselected set of OpenERP "
85                  "applications selected to help you manage your auctions "
86                  "as well as the business processes around them."),
87         }
88
89     def _if_knowledge(self, cr, uid, ids, context=None):
90         if self.pool.get('res.users').browse(cr, uid, uid, context=context)\
91                .view == 'simple':
92             return ['document_ftp']
93         return None
94
95     def _if_misc_tools(self, cr, uid, ids, context=None):
96         return ['profile_tools']
97
98     def onchange_moduleselection(self, cr, uid, ids, *args, **kargs):
99         value = {}
100         # Calculate progress
101         closed, total = self.get_current_progress(cr, uid)
102         progress = round(100. * closed / (total + len(filter(None, args))))
103         value.update({'progress':progress})
104         if progress < 10.:
105             progress = 10.
106         
107         return {'value':value}
108
109
110     def execute(self, cr, uid, ids, context=None):
111         if context is None:
112              context = {}
113         module_pool = self.pool.get('ir.module.module')
114         modules_selected = []
115         datas = self.read(cr, uid, ids, context=context)[0]
116         for mod in datas.keys():
117             if mod in ('id', 'progress'):
118                 continue
119             if datas[mod] == 1:
120                 modules_selected.append(mod)
121
122         module_ids = module_pool.search(cr, uid, [('name', 'in', modules_selected)], context=context)
123         for module in module_pool.browse(cr, uid, module_ids, context=context):
124             if module.state == 'uninstalled':
125                 module_pool.state_update(cr, uid, [module.id], 'to install', ['uninstalled'], context)
126                 cr.commit()
127                 new_db, self.pool = pooler.restart_pool(cr.dbname, update_module=True)
128             elif module.state == 'installed':
129                 cr.execute("update ir_actions_todo set state='open' \
130                                     from ir_model_data as data where data.res_id = ir_actions_todo.id \
131                                     and ir_actions_todo.type='special'\
132                                     and data.model = 'ir.actions.todo' and data.module=%s", (module.name, ))
133         return
134     
135 base_setup_installer()
136
137 #Migrate data from another application Conf wiz
138
139 class migrade_application_installer_modules(osv.osv_memory):
140     _name = 'migrade.application.installer.modules'
141     _inherit = 'res.config.installer'
142     _columns = {
143         'import_saleforce': fields.boolean('Import Saleforce',
144             help="For Import Saleforce"),
145         'import_sugarcrm': fields.boolean('Import Sugarcrm',
146             help="For Import Sugarcrm"),
147         'sync_google_contact': fields.boolean('Sync Google Contact',
148             help="For Sync Google Contact"),
149         'quickbooks_ippids': fields.boolean('Quickbooks Ippids',
150             help="For Quickbooks Ippids"),
151     }
152     
153 migrade_application_installer_modules()
154
155 class product_installer(osv.osv_memory):
156     _name = 'product.installer'
157     _inherit = 'res.config'
158     _columns = {
159                 'customers': fields.selection([('create','Create'), ('import','Import')], 'Customers', size=32, required=True, help="Import or create customers"),
160
161     }
162     _defaults = {
163                  'customers': 'create',
164     }
165     
166     def execute(self, cr, uid, ids, context=None):
167         if context is None:
168              context = {}
169         data_obj = self.pool.get('ir.model.data')
170         val = self.browse(cr, uid, ids, context=context)[0]
171         if val.customers == 'create':
172             id2 = data_obj._get_id(cr, uid, 'base', 'view_partner_form')
173             if id2:
174                 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
175             return {
176                     'view_type': 'form',
177                     'view_mode': 'form',
178                     'res_model': 'res.partner',
179                     'views': [(id2, 'form')],
180                     'type': 'ir.actions.act_window',
181                     'target': 'current',
182                     'nodestroy':False,
183                 }
184         if val.customers == 'import':
185             return {'type': 'ir.actions.act_window'}
186
187 product_installer()
188
189
190 #       Define default users preferences config wiz
191
192 def _lang_get(self, cr, uid, context=None):
193     obj = self.pool.get('res.lang')
194     ids = obj.search(cr, uid, [('translatable','=',True)])
195     res = obj.read(cr, uid, ids, ['code', 'name'], context=context)
196     res = [(r['code'], r['name']) for r in res]
197     return res
198
199 def _tz_get(self,cr,uid, context=None):
200     return [(x, x) for x in pytz.all_timezones]
201
202 class user_preferences_config(osv.osv_memory):
203     _name = 'user.preferences.config'
204     _inherit = 'res.config'
205     _columns = {
206         'context_tz': fields.selection(_tz_get,  'Timezone', size=64,
207             help="Set default for new user's timezone, used to perform timezone conversions "
208                  "between the server and the client."),
209         'context_lang': fields.selection(_lang_get, 'Language', required=True,
210             help="Sets default language for the  new user's user interface, when UI "
211                  "translations are available"),
212         'view': fields.selection([('simple','Simplified'),
213                                   ('extended','Extended')],
214                                  'Interface', required=True, help= "If you use OpenERP for the first time we strongly advise you to select the simplified interface, which has less features but is easier. You can always switch later from the user preferences." ),
215         'menu_tips': fields.boolean('Display Tips', help="Check out this box if you want to always display tips on each menu action"),
216                                  
217     }
218     _defaults={
219                'view' : lambda self,cr,uid,*args: self.pool.get('res.users').browse(cr, uid, uid).view or 'simple',
220                'context_lang' : 'en_US',
221                'menu_tips' : True
222     }
223     
224     def default_get(self, cr, uid, fields, context=None):
225         if context is None:
226             context = {}
227         res = super(user_preferences_config, self).default_get(cr, uid, fields, context=context)
228         res_default = self.pool.get('ir.values').get(cr, uid, 'default', False, ['res.users'])
229         for id, field, value in res_default:
230             res.update({field: value})
231         return res
232
233     def execute(self, cr, uid, ids, context=None):
234         for o in self.browse(cr, uid, ids, context=context):
235             ir_values_obj = self.pool.get('ir.values')
236             ir_values_obj.set(cr, uid, 'default', False, 'context_tz', ['res.users'], o.context_tz)
237             ir_values_obj.set(cr, uid, 'default', False, 'context_lang', ['res.users'], o.context_lang)
238             ir_values_obj.set(cr, uid, 'default', False, 'view', ['res.users'], o.view)
239             ir_values_obj.set(cr, uid, 'default', False, 'menu_tips', ['res.users'], o.menu_tips)
240         return {}
241
242 user_preferences_config()
243
244 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: