[IMP]Base Setup:Create New Conf wiz- Migrate data from another application
[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
24 class base_setup_installer(osv.osv_memory):
25     _name = 'base.setup.installer'
26     _inherit = 'res.config.installer'
27
28     _install_if = {
29         ('sale','crm'): ['sale_crm'],
30         ('sale','project'): ['project_mrp'],
31     }
32     _columns = {
33         # Generic modules
34         'crm':fields.boolean('Customer Relationship Management',
35             help="Helps you track and manage relations with customers such as"
36                  " leads, requests or issues. Can automatically send "
37                  "reminders, escalate requests or trigger business-specific "
38                  "actions based on standard events."),
39         'sale':fields.boolean('Sales Management',
40             help="Helps you handle your quotations, sale orders and invoicing"
41                  "."),
42         'project':fields.boolean('Project Management',
43             help="Helps you manage your projects and tasks by tracking them, "
44                  "generating plannings, etc..."),
45         'knowledge':fields.boolean('Knowledge Management',
46             help="Lets you install addons geared towards sharing knowledge "
47                  "with and between your employees."),
48         'stock':fields.boolean('Warehouse Management',
49             help="Helps you manage your inventory and main stock operations: delivery orders, receptions, etc."),
50         'mrp':fields.boolean('Manufacturing',
51             help="Helps you manage your manufacturing processes and generate "
52                  "reports on those processes."),
53         'account_voucher':fields.boolean('Invoicing',
54             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."),
55         'account_accountant':fields.boolean('Accounting & Finance',
56             help="Helps you handle your accounting needs, if you are not an accountant, we suggest you to install only the Invoicing "),
57         'purchase':fields.boolean('Purchase Management',
58             help="Helps you manage your purchase-related processes such as "
59                  "requests for quotations, supplier invoices, etc..."),
60         'hr':fields.boolean('Human Resources',
61             help="Helps you manage your human resources by encoding your employees structure, generating work sheets, tracking attendance and more."),
62         'point_of_sale':fields.boolean('Point of Sales',
63             help="Helps you get the most out of your points of sales with "
64                  "fast sale encoding, simplified payment mode encoding, "
65                  "automatic picking lists generation and more."),
66         'marketing':fields.boolean('Marketing',
67             help="Helps you manage your marketing campaigns step by step."),
68         'profile_tools':fields.boolean('Extra Tools',
69             help="Lets you install various interesting but non-essential tools "
70                 "like Survey, Lunch and Ideas box."),
71         'report_designer':fields.boolean('Advanced Reporting',
72             help="Lets you install various tools to simplify and enhance "
73                  "OpenERP's report creation."),
74         # Vertical modules
75         'product_expiry':fields.boolean('Food Industry',
76             help="Installs a preselected set of OpenERP applications "
77                 "which will help you manage your industry."),
78         'association':fields.boolean('Associations',
79             help="Installs a preselected set of OpenERP "
80                  "applications which will help you manage your association "
81                  "more efficiently."),
82         'auction':fields.boolean('Auction Houses',
83             help="Installs a preselected set of OpenERP "
84                  "applications selected to help you manage your auctions "
85                  "as well as the business processes around them."),
86         }
87
88     def _if_knowledge(self, cr, uid, ids, context=None):
89         if self.pool.get('res.users').browse(cr, uid, uid, context=context)\
90                .view == 'simple':
91             return ['document_ftp']
92         return None
93
94     def _if_misc_tools(self, cr, uid, ids, context=None):
95         return ['profile_tools']
96
97     def onchange_moduleselection(self, cr, uid, ids, *args, **kargs):
98         value = {}
99         # Calculate progress
100         closed, total = self.get_current_progress(cr, uid)
101         progress = round(100. * closed / (total + len(filter(None, args))))
102         value.update({'progress':progress})
103         if progress < 10.:
104             progress = 10.
105         
106         return {'value':value}
107     
108
109     def default_get(self, cr, uid, fields_list, context=None):
110         #Skipping default value as checked for main application, if already installed
111         return super(osv.osv_memory, self).default_get(
112             cr, uid, fields_list, context=context)
113
114     def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
115         #Skipping readonly value for main application, if already installed
116         return super(osv.osv_memory, self).fields_get(
117             cr, uid, fields, context, write_access)
118
119     def execute(self, cr, uid, ids, context=None):
120         if context is None:
121              context = {}
122         modules = self.pool.get('ir.module.module')
123         modules_selected = []
124         datas = self.read(cr, uid, ids, context=context)[0]
125         key = datas.keys()
126         key.remove("id")
127         key.remove("progress")
128         name_list = []
129         for mod in key:
130             if datas[mod] == 1:
131                 modules_selected.append(mod)
132         inst = modules.browse(
133             cr, uid,
134             modules.search(cr, uid,
135                            [('name','in',modules_selected)
136                             ],
137                            context=context),
138             context=context)
139         for i in inst:
140             if i.state == 'uninstalled':
141                 sect_mod_id = i.id
142                 modules.state_update(cr, uid, [sect_mod_id], 'to install', ['uninstalled'], context)
143                 cr.commit()
144                 new_db, self.pool = pooler.restart_pool(cr.dbname, update_module=True)
145             elif i.state == 'installed':
146                 if modules_selected:
147                     for instl in modules_selected:
148                         cr.execute("update ir_actions_todo set restart='on_trigger' , state='open' from ir_model_data as data where data.res_id = ir_actions_todo.id and data.model =  'ir.actions.todo' and data.module  like '%"+instl+"%'")
149         
150         return 
151     
152 base_setup_installer()
153
154 #Migrate data from another application Conf wiz
155
156 class migrade_application_installer_modules(osv.osv_memory):
157     _name = 'migrade.application.installer.modules'
158     _inherit = 'res.config.installer'
159     _columns = {
160         'import_saleforce': fields.boolean('Import Saleforce',
161             help="For Import Saleforce"),
162         'import_sugarcrm': fields.boolean('Import Sugarcrm',
163             help="For Import Sugarcrm"),
164         'sync_google_contact': fields.boolean('Sync Google Contact',
165             help="For Sync Google Contact"),
166         'quickbooks_ippids': fields.boolean('Quickbooks Ippids',
167             help="For Quickbooks Ippids"),
168     }
169     
170     _defaults = {
171         'import_saleforce': True,
172     }
173
174 migrade_application_installer_modules()
175
176 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: