# -*- 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 class ir_module_category(osv.osv): _inherit = 'ir.module.category' _columns = { 'module_ids' : fields.one2many('ir.module.module', 'category_id', 'Modules'), } ir_module_category() #Application and feature chooser, this could be done by introspecting ir.modules class base_setup_installer2(osv.osv_memory): _name = 'base.setup.installer2' _inherit = 'res.config.installer' _columns = { 'modules' : fields.text('Modules'), } 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', '!=', 'Localization')] 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' category_name = 'category_%d' % (module.category_id.id,) if not result.get('category_name'): result[category_name] = module.state == 'installed' return result def fields_view_get(self, cr, uid, view_id=None, view_type='from', context=None, toolbar=False, submenu=False): result = super(base_setup_installer2, 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', '!=', 'Localization')] module_category_ids = module_category_proxy.search(cr, uid, domain, context=context, order='name asc') arch = ['
' % _('Automatic Base Setup')] arch.append('' % _('Categories')) for module_category in module_category_proxy.browse(cr, uid, module_category_ids, context=context): readonly = False for module in module_category.module_ids: if module.state == 'installed': readonly=True attributes = { 'name' : 'category_%d' % (module_category.id,), 'on_change' : 'on_change_selection("category_%d")' % (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 module to show for module_category in module_category_proxy.browse(cr, uid, module_category_ids, context=context): if not module_category.module_ids: continue modifiers = { 'invisible' : [('category_%d' % (module_category.id), '=', False)], 'readonly' : module.state == 'installed', } modifiers = simplejson.dumps(modifiers) arch.append("""""" % (cgi.escape(module_category.name), modifiers)) for module in module_category.module_ids: arch.append("""""" % (module.id, modifiers)) arch.append( '' '' '