# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## import pytz import simplejson import cgi import pooler import tools from osv import fields, osv from tools.translate import _ from lxml import etree #Application and feature chooser, this could be done by introspecting ir.modules DEFAULT_MODULES = { 'Customer Relationship Management' : ['crm',], 'Sales Management' : ['sale',], 'Project Management' : ['project',], 'Knowledge Management' : ['document',], 'Warehouse Management' : ['stock',], 'Manufacturing' : ['mrp'], 'Accounting & Finance' : ['account'], 'Purchase Management' : ['purchase'], 'Human Resources' : ['hr',], 'Point of Sale' : ['point_of_sale',], 'Marketing' : ['marketing',], } class base_setup_installer(osv.osv_memory): _name = 'base.setup.installer' _inherit = 'res.config.installer' _columns = { 'selection' : fields.text('Selection'), } def fields_get(self, cr, uid, fields=None, context=None): if context is None: context = {} if fields is None: fields = {} fields = {} category_proxy = self.pool.get('ir.module.category') domain = [('parent_id', '=', False), ('name', '!=', 'Uncategorized'), ('visible', '=', True)] category_ids = category_proxy.search(cr, uid, domain, context=context) for category in category_proxy.browse(cr, uid, category_ids, context=context): category_name = 'category_%d' % (category.id,) fields[category_name] = { 'type' : 'boolean', 'string' : category.name, 'name' : category_name, 'help' : category.description, } module_proxy = self.pool.get('ir.module.module') module_ids = module_proxy.search(cr, uid, [], context=context) for module in module_proxy.browse(cr, uid, module_ids, context=context): module_name = 'module_%d' % (module.id,) module_is_installed = module.state == 'installed' fields[module_name] = { 'type' : 'boolean', 'string' : module.shortdesc, 'name' : module_name, 'help' : module.description, } return fields def default_get(self, cr, uid, fields=None, context=None): if context is None: context = {} if fields is None: fields = {} result = {} if 'dont_compute_virtual_attributes' not in context: module_proxy = self.pool.get('ir.module.module') module_ids = module_proxy.search(cr, uid, [], context=context) for module in module_proxy.browse(cr, uid, module_ids, context=context): result['module_%d' % (module.id,)] = module.state == 'installed' cat_proxy = self.pool.get('ir.module.category') cat_ids = cat_proxy.search(cr, uid, [], context=context) for cat in cat_proxy.browse(cr, uid, cat_ids, context=context): m = DEFAULT_MODULES.get(cat.name,[]) r = module_proxy.search(cr, uid, [('state','=','installed'),('name','in',m)]) result['category_%d' % (cat.id,)] = bool(r) and (len(r) == len(m)) return result def fields_view_get(self, cr, uid, view_id=None, view_type='from', context=None, toolbar=False, submenu=False): def in_extended_view_group(cr, uid, context=None): try: model, group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_extended') except ValueError: return False return group_id in self.pool.get('res.users').read(cr, uid, uid, ['groups_id'], context=context)['groups_id'] result = super(base_setup_installer, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) module_category_proxy = self.pool.get('ir.module.category') domain = [('parent_id', '=', False), ('name', '!=', 'Uncategorized'), ('visible', '=', True)] module_category_ids = module_category_proxy.search(cr, uid, domain, context=context, order='sequence asc') arch = ['
' % _('Automatic Base Setup')] arch.append('' % _('Install Applications')) module_proxy = self.pool.get('ir.module.module') extended_view = in_extended_view_group(cr, uid, context=context) for module_category in module_category_proxy.browse(cr, uid, module_category_ids, context=context): domain = [('category_id', '=', module_category.id)] if not extended_view: domain.append(('complexity', '!=', 'expert')) modules = module_proxy.browse(cr, uid, module_proxy.search(cr, uid, domain, context=context), context=context) if not modules: continue m = DEFAULT_MODULES.get(module_category.name, []) r = module_proxy.search(cr, uid, [('state', '=', 'installed'),('name', 'in', m)], context=context) readonly = bool(r) attributes = { 'name' : 'category_%d' % (module_category.id,), 'on_change' : 'on_change_%s_%d(category_%d)' % ('category', module_category.id, module_category.id,), } if readonly: attributes['modifiers'] = simplejson.dumps({'readonly' : True}) arch.append("""""" % (" ".join(["%s='%s'" % (key, value,) for key, value in attributes.iteritems()]),)) # Compute the modules to show for module_category in module_category_proxy.browse(cr, uid, module_category_ids, context=context): domain = [('category_id', '=', module_category.id)] if not extended_view: domain.append(('complexity', '!=', 'expert')) default_modules = DEFAULT_MODULES.get(module_category.name, False) if default_modules: domain.append(('name', 'not in', default_modules)) modules = module_proxy.browse(cr, uid, module_proxy.search(cr, uid, domain, context=context), context=context) if not modules: continue modifiers = { 'invisible' : [('category_%d' % (module_category.id), '=', False)], } module_modifiers = dict(modifiers) arch.append("""""" % ( cgi.escape(module_category.name), simplejson.dumps(modifiers)) ) for module in modules: #module_modifiers['readonly'] = module.state == 'installed' arch.append("""""" % ( module.id, simplejson.dumps(module_modifiers)) ) arch.append( '' '' '