[FIX] Fix graph canvas height width.
[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 from tools.translate import _
25 import tools
26
27 class base_setup_installer(osv.osv_memory):
28     _name = 'base.setup.installer'
29     _inherit = 'res.config.installer'
30
31     _install_if = {
32         ('sale','crm'): ['sale_crm'],
33         ('sale','project'): ['project_mrp'],
34     }
35     _columns = {
36         # Generic modules
37         'crm':fields.boolean('Customer Relationship Management',
38             help="Helps you track and manage relations with customers such as"
39                  " leads, requests or issues. Can automatically send "
40                  "reminders, escalate requests or trigger business-specific "
41                  "actions based on standard events."),
42         'sale':fields.boolean('Sales Management',
43             help="Helps you handle your quotations, sale orders and invoicing"
44                  "."),
45         'project':fields.boolean('Project Management',
46             help="Helps you manage your projects and tasks by tracking them, "
47                  "generating plannings, etc..."),
48         'knowledge':fields.boolean('Knowledge Management',
49             help="Lets you install addons geared towards sharing knowledge "
50                  "with and between your employees."),
51         'stock':fields.boolean('Warehouse Management',
52             help="Helps you manage your inventory and main stock operations: delivery orders, receptions, etc."),
53         'mrp':fields.boolean('Manufacturing',
54             help="Helps you manage your manufacturing processes and generate "
55                  "reports on those processes."),
56         'account_voucher':fields.boolean('Invoicing & Payments',
57             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."),
58         'account_accountant':fields.boolean('Accounting & Finance',
59             help="Helps you handle your accounting needs, if you are not an accountant, we suggest you to install only the Invoicing "),
60         'purchase':fields.boolean('Purchase Management',
61             help="Helps you manage your purchase-related processes such as "
62                  "requests for quotations, supplier invoices, etc..."),
63         'hr':fields.boolean('Human Resources',
64             help="Helps you manage your human resources by encoding your employees structure, generating work sheets, tracking attendance and more."),
65         'point_of_sale':fields.boolean('Point of Sales',
66             help="Helps you get the most out of your points of sales with "
67                  "fast sale encoding, simplified payment mode encoding, "
68                  "automatic picking lists generation and more."),
69         'marketing':fields.boolean('Marketing',
70             help="Helps you manage your marketing campaigns step by step."),
71         'profile_tools':fields.boolean('Extra Tools',
72             help="Lets you install various interesting but non-essential tools "
73                 "like Survey, Lunch and Ideas box."),
74         'report_designer':fields.boolean('Advanced Reporting',
75             help="Lets you install various tools to simplify and enhance "
76                  "OpenERP's report creation."),
77         # Vertical modules
78         'product_expiry':fields.boolean('Food Industry',
79             help="Installs a preselected set of OpenERP applications "
80                 "which will help you manage your industry."),
81         'association':fields.boolean('Associations',
82             help="Installs a preselected set of OpenERP "
83                  "applications which will help you manage your association "
84                  "more efficiently."),
85         'auction':fields.boolean('Auction Houses',
86             help="Installs a preselected set of OpenERP "
87                  "applications selected to help you manage your auctions "
88                  "as well as the business processes around them."),
89         }
90
91     def _if_knowledge(self, cr, uid, ids, context=None):
92         if self.pool.get('res.users').browse(cr, uid, uid, context=context)\
93                .view == 'simple':
94             return ['document_ftp']
95         return None
96
97     def _if_misc_tools(self, cr, uid, ids, context=None):
98         return ['profile_tools']
99
100     def onchange_moduleselection(self, cr, uid, ids, *args, **kargs):
101         value = {}
102         # Calculate progress
103         closed, total = self.get_current_progress(cr, uid)
104         progress = round(100. * closed / (total + len(filter(None, args))))
105         value.update({'progress':progress})
106         if progress < 10.:
107             progress = 10.
108         
109         return {'value':value}
110
111
112     def execute(self, cr, uid, ids, context=None):
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         need_install = False
124         for module in module_pool.browse(cr, uid, module_ids, context=context):
125             if module.state == 'uninstalled':
126                 module_pool.state_update(cr, uid, [module.id], 'to install', ['uninstalled'], context)
127                 need_install = True
128                 cr.commit()
129             elif module.state == 'installed':
130                 cr.execute("update ir_actions_todo set state='open' \
131                                     from ir_model_data as data where data.res_id = ir_actions_todo.id \
132                                     and ir_actions_todo.type='special'\
133                                     and data.model = 'ir.actions.todo' and data.module=%s", (module.name, ))
134         if need_install:
135             self.pool = pooler.restart_pool(cr.dbname, update_module=True)[1]
136         return
137     
138 base_setup_installer()
139
140 #Migrate data from another application Conf wiz
141
142 class migrade_application_installer_modules(osv.osv_memory):
143     _name = 'migrade.application.installer.modules'
144     _inherit = 'res.config.installer'
145     _columns = {
146         'import_saleforce': fields.boolean('Import Saleforce',
147             help="For Import Saleforce"),
148         'import_sugarcrm': fields.boolean('Import Sugarcrm',
149             help="For Import Sugarcrm"),
150         'sync_google_contact': fields.boolean('Sync Google Contact',
151             help="For Sync Google Contact"),
152         'quickbooks_ippids': fields.boolean('Quickbooks Ippids',
153             help="For Quickbooks Ippids"),
154     }
155     
156 migrade_application_installer_modules()
157
158 class product_installer(osv.osv_memory):
159     _name = 'product.installer'
160     _inherit = 'res.config'
161     _columns = {
162                 'customers': fields.selection([('create','Create'), ('import','Import')], 'Customers', size=32, required=True, help="Import or create customers"),
163
164     }
165     _defaults = {
166                  'customers': 'create',
167     }
168     
169     def execute(self, cr, uid, ids, context=None):
170         if context is None:
171              context = {}
172         data_obj = self.pool.get('ir.model.data')
173         val = self.browse(cr, uid, ids, context=context)[0]
174         if val.customers == 'create':
175             id2 = data_obj._get_id(cr, uid, 'base', 'view_partner_form')
176             if id2:
177                 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
178             return {
179                     'view_type': 'form',
180                     'view_mode': 'form',
181                     'res_model': 'res.partner',
182                     'views': [(id2, 'form')],
183                     'type': 'ir.actions.act_window',
184                     'target': 'current',
185                     'nodestroy':False,
186                 }
187         if val.customers == 'import':
188             return {'type': 'ir.actions.act_window'}
189
190 product_installer()
191
192
193 #       Define default users preferences config wiz
194
195 def _lang_get(self, cr, uid, context=None):
196     obj = self.pool.get('res.lang')
197     ids = obj.search(cr, uid, [('translatable','=',True)])
198     res = obj.read(cr, uid, ids, ['code', 'name'], context=context)
199     res = [(r['code'], r['name']) for r in res]
200     return res
201
202 def _tz_get(self,cr,uid, context=None):
203     return [(x, x) for x in pytz.all_timezones]
204
205 class user_preferences_config(osv.osv_memory):
206     _name = 'user.preferences.config'
207     _inherit = 'res.config'
208     _columns = {
209         'context_tz': fields.selection(_tz_get,  'Timezone', size=64,
210             help="Set default for new user's timezone, used to perform timezone conversions "
211                  "between the server and the client."),
212         'context_lang': fields.selection(_lang_get, 'Language', required=True,
213             help="Sets default language for the all user interface, when UI "
214                 "translations are available. If you want to Add new Language, you can add it from 'Load an Official Translation' wizard  from 'Administration' menu."),
215         'view': fields.selection([('simple','Simplified'),
216                                   ('extended','Extended')],
217                                  '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." ),
218         'menu_tips': fields.boolean('Display Tips', help="Check out this box if you want to always display tips on each menu action"),
219                                  
220     }
221     _defaults={
222                'view' : lambda self,cr,uid,*args: self.pool.get('res.users').browse(cr, uid, uid).view or 'simple',
223                'context_lang' : 'en_US',
224                'menu_tips' : True
225     }
226     
227     def default_get(self, cr, uid, fields, context=None):
228         if context is None:
229             context = {}
230         res = super(user_preferences_config, self).default_get(cr, uid, fields, context=context)
231         res_default = self.pool.get('ir.values').get(cr, uid, 'default', False, ['res.users'])
232         for id, field, value in res_default:
233             res.update({field: value})
234         return res
235
236     def execute(self, cr, uid, ids, context=None):
237         user_obj = self.pool.get('res.users')
238         user_ids = user_obj.search(cr, uid, [], context=context)
239         for o in self.browse(cr, uid, ids, context=context):
240             user_obj.write(cr , uid, user_ids ,{'context_tz' : o.context_tz, 'context_lang' : o.context_lang, 'view' : o.view, 'menu_tips' : o.menu_tips}, context=context)
241             ir_values_obj = self.pool.get('ir.values')
242             ir_values_obj.set(cr, uid, 'default', False, 'context_tz', ['res.users'], o.context_tz)
243             ir_values_obj.set(cr, uid, 'default', False, 'context_lang', ['res.users'], o.context_lang)
244             ir_values_obj.set(cr, uid, 'default', False, 'view', ['res.users'], o.view)
245             ir_values_obj.set(cr, uid, 'default', False, 'menu_tips', ['res.users'], o.menu_tips)
246         return {}
247
248 user_preferences_config()
249
250 # Specify Your Terminology
251
252 class specify_partner_terminology(osv.osv_memory):
253     _name = 'specify.partner.terminology'
254     _inherit = 'res.config'
255     _columns = {
256         'partner': fields.selection([('Customer','Customer'),
257                                   ('Client','Client'),
258                                   ('Member','Member'),
259                                   ('Patient','Patient'),
260                                   ('Partner','Partner'),
261                                   ('Donor','Donor'),
262                                   ('Guest','Guest'),
263                                   ('Tenant','Tenant')
264                                   ],
265                                  'Choose how to call a Customer', required=True ),
266     }
267     _defaults={
268                'partner' :'Partner',
269     }
270     
271     def make_translations(self, cr, uid, ids, name, type, src, value, res_id=0, context=None):
272         trans_obj = self.pool.get('ir.translation')
273         user_obj = self.pool.get('res.users')
274         context_lang = user_obj.browse(cr, uid, uid, context=context).context_lang
275         existing_trans_ids = trans_obj.search(cr, uid, [('name','=',name), ('lang','=',context_lang), ('type','=',type), ('src','=',src), ('res_id','=',res_id)])
276         if existing_trans_ids:
277             trans_obj.write(cr, uid, existing_trans_ids, {'value': value}, context=context)
278         else:
279             create_id = trans_obj.create(cr, uid, {'name': name,'lang': context_lang, 'type': type, 'src': src, 'value': value , 'res_id': res_id}, context=context)
280         return {}
281     
282     def execute(self, cr, uid, ids, context=None):
283         def _case_insensitive_replace(ref_string, src, value):
284             import re
285             pattern = re.compile(src, re.IGNORECASE)
286             return pattern.sub(_(value), _(ref_string))
287         trans_obj = self.pool.get('ir.translation')
288         fields_obj = self.pool.get('ir.model.fields')
289         menu_obj = self.pool.get('ir.ui.menu')
290         act_window_obj = self.pool.get('ir.actions.act_window')
291         for o in self.browse(cr, uid, ids, context=context):
292             #translate label of field
293             field_ids = fields_obj.search(cr, uid, [('field_description','ilike','Customer')])
294             for f_id in fields_obj.browse(cr ,uid, field_ids, context=context):
295                 field_ref = f_id.model_id.model + ',' + f_id.name
296                 self.make_translations(cr, uid, ids, field_ref, 'field', f_id.field_description, _case_insensitive_replace(f_id.field_description,'Customer',o.partner), context=context)
297             #translate help tooltip of field
298             for obj in self.pool.obj_pool.values():
299                 for field_name, field_rec in obj._columns.items():
300                     if field_rec.help.lower().count('customer'):
301                         field_ref = obj._name + ',' + field_name
302                         self.make_translations(cr, uid, ids, field_ref, 'help', field_rec.help, _case_insensitive_replace(field_rec.help,'Customer',o.partner), context=context)
303             #translate menuitems
304             menu_ids = menu_obj.search(cr,uid, [('name','ilike','Customer')])
305             for m_id in menu_obj.browse(cr, uid, menu_ids, context=context):
306                 menu_name = m_id.name
307                 menu_ref = 'ir.ui.menu' + ',' + 'name'
308                 self.make_translations(cr, uid, ids, menu_ref, 'model', menu_name, _case_insensitive_replace(menu_name,'Customer',o.partner), res_id=m_id.id, context=context)
309             #translate act window name
310             act_window_ids = act_window_obj.search(cr, uid, [('name','ilike','Customer')])
311             for act_id in act_window_obj.browse(cr ,uid, act_window_ids, context=context):
312                 act_ref = 'ir.actions.act_window' + ',' + 'name'
313                 self.make_translations(cr, uid, ids, act_ref, 'model', act_id.name, _case_insensitive_replace(act_id.name,'Customer',o.partner), res_id=act_id.id, context=context)
314             #translate act window tooltips
315             act_window_ids = act_window_obj.search(cr, uid, [('help','ilike','Customer')])
316             for act_id in act_window_obj.browse(cr ,uid, act_window_ids, context=context):
317                 act_ref = 'ir.actions.act_window' + ',' + 'help'
318                 self.make_translations(cr, uid, ids, act_ref, 'model', act_id.help, _case_insensitive_replace(act_id.help,'Customer',o.partner), res_id=act_id.id, context=context)
319         return {}
320     
321 specify_partner_terminology()
322
323
324 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: