2009-12-03 15:11:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2009-12-04 12:14:52 +00:00
|
|
|
from osv import osv, fields
|
2009-12-03 15:11:22 +00:00
|
|
|
import netsvc
|
2010-01-06 07:53:30 +00:00
|
|
|
import pooler
|
2009-12-03 15:11:22 +00:00
|
|
|
|
|
|
|
class res_config_configurable(osv.osv_memory):
|
2009-12-10 07:34:13 +00:00
|
|
|
''' Base classes for new-style configuration items
|
|
|
|
|
|
|
|
Configuration items should inherit from this class, implement
|
|
|
|
the execute method (and optionally the cancel one) and have
|
|
|
|
their view inherit from the related res_config_view_base view.
|
|
|
|
'''
|
2009-12-04 10:58:21 +00:00
|
|
|
_name = 'res.config'
|
2009-12-03 15:11:22 +00:00
|
|
|
logger = netsvc.Logger()
|
|
|
|
|
2009-12-04 12:14:52 +00:00
|
|
|
def _progress(self, cr, uid, context=None):
|
|
|
|
total = self.pool.get('ir.actions.todo')\
|
|
|
|
.search_count(cr, uid, [], context)
|
|
|
|
open = self.pool.get('ir.actions.todo')\
|
2009-12-07 10:17:40 +00:00
|
|
|
.search_count(cr, uid, [('active','=',True),
|
|
|
|
('state','<>','open')],
|
2009-12-04 12:14:52 +00:00
|
|
|
context)
|
|
|
|
if total:
|
|
|
|
return round(open*100./total)
|
|
|
|
return 100.
|
|
|
|
|
|
|
|
_columns = dict(
|
|
|
|
progress=fields.float('Configuration Progress', readonly=True),
|
|
|
|
)
|
|
|
|
_defaults = dict(
|
|
|
|
progress=_progress
|
|
|
|
)
|
|
|
|
|
2009-12-03 15:11:22 +00:00
|
|
|
def _next_action(self, cr, uid):
|
|
|
|
todos = self.pool.get('ir.actions.todo')
|
|
|
|
self.logger.notifyChannel('actions', netsvc.LOG_INFO,
|
|
|
|
'getting next %s' % todos)
|
2009-12-07 10:17:40 +00:00
|
|
|
active_todos = todos.search(cr, uid, [('state','=','open'),
|
|
|
|
('active','=',True)],
|
|
|
|
limit=1, context=None)
|
2009-12-03 15:11:22 +00:00
|
|
|
if active_todos:
|
|
|
|
return todos.browse(cr, uid, active_todos[0], context=None)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def _next(self, cr, uid):
|
|
|
|
self.logger.notifyChannel('actions', netsvc.LOG_INFO,
|
|
|
|
'getting next operation')
|
|
|
|
next = self._next_action(cr, uid)
|
|
|
|
self.logger.notifyChannel('actions', netsvc.LOG_INFO,
|
|
|
|
'next action is %s' % next)
|
|
|
|
if next:
|
|
|
|
self.pool.get('ir.actions.todo').write(cr, uid, next.id, {
|
|
|
|
'state':'done',
|
|
|
|
}, context=None)
|
|
|
|
action = next.action_id
|
|
|
|
return {
|
|
|
|
'view_mode': action.view_mode,
|
|
|
|
'view_type': action.view_type,
|
|
|
|
'view_id': action.view_id and [action.view_id.id] or False,
|
|
|
|
'res_model': action.res_model,
|
|
|
|
'type': action.type,
|
|
|
|
'target': action.target,
|
|
|
|
}
|
|
|
|
self.logger.notifyChannel(
|
|
|
|
'actions', netsvc.LOG_INFO,
|
|
|
|
'all configuration actions have been executed')
|
2009-12-16 13:33:35 +00:00
|
|
|
|
|
|
|
current_user_menu = self.pool.get('res.users')\
|
|
|
|
.browse(cr, uid, uid).menu_id
|
|
|
|
# return the action associated with the menu
|
|
|
|
return self.pool.get(current_user_menu.type)\
|
|
|
|
.read(cr, uid, current_user_menu.id)
|
2009-12-10 08:06:50 +00:00
|
|
|
def next(self, cr, uid, ids, context=None):
|
2009-12-03 15:11:22 +00:00
|
|
|
return self._next(cr, uid)
|
2009-12-10 07:32:13 +00:00
|
|
|
|
|
|
|
def execute(self, cr, uid, ids, context=None):
|
|
|
|
raise NotImplementedError(
|
|
|
|
'Configuration items need to implement execute')
|
|
|
|
def cancel(self, cr, uid, ids, context=None):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def action_next(self, cr, uid, ids, context=None):
|
|
|
|
next = self.execute(cr, uid, ids, context=None)
|
|
|
|
if next: return next
|
2009-12-10 08:06:50 +00:00
|
|
|
return self.next(cr, uid, ids, context=context)
|
|
|
|
|
2009-12-10 07:32:13 +00:00
|
|
|
def action_skip(self, cr, uid, ids, context=None):
|
|
|
|
next = self.cancel(cr, uid, ids, context=None)
|
|
|
|
if next: return next
|
2009-12-10 08:06:50 +00:00
|
|
|
return self.next(cr, uid, ids, context=context)
|
2009-12-03 15:11:22 +00:00
|
|
|
res_config_configurable()
|
|
|
|
|
2010-01-06 07:53:30 +00:00
|
|
|
class res_config_installer(osv.osv_memory):
|
|
|
|
''' New-style configuration base specialized for modules selection
|
|
|
|
and installation.
|
|
|
|
'''
|
|
|
|
_name = 'res.config.installer'
|
|
|
|
_inherit = 'res.config'
|
|
|
|
|
|
|
|
def execute(self, cr, uid, ids, context=None):
|
|
|
|
modules = self.pool.get('ir.module.module')
|
|
|
|
|
|
|
|
for installer in self.read(cr, uid, ids):
|
|
|
|
for addon_name, to_install in installer.iteritems():
|
|
|
|
if addon_name != 'id' and to_install:
|
|
|
|
self.logger.notifyChannel(
|
|
|
|
'installer', netsvc.LOG_INFO,
|
|
|
|
'Selecting addon "%s" to install'%addon_name)
|
|
|
|
modules.button_install(
|
|
|
|
cr, uid,
|
|
|
|
modules.search(cr, uid, [('name','=',addon_name)]),
|
|
|
|
context=context)
|
|
|
|
cr.commit()
|
|
|
|
|
|
|
|
pooler.restart_pool(cr.dbname, update_module=True)
|
|
|
|
res_config_installer()
|
|
|
|
|
2009-12-17 14:19:35 +00:00
|
|
|
DEPRECATION_MESSAGE = 'You are using an addon using old-style configuration '\
|
|
|
|
'wizards (ir.actions.configuration.wizard). Old-style configuration '\
|
|
|
|
'wizards have been deprecated.\n'\
|
|
|
|
'The addon should be migrated to res.config objects.'
|
2009-12-16 15:59:41 +00:00
|
|
|
class ir_actions_configuration_wizard(osv.osv_memory):
|
|
|
|
''' Compatibility configuration wizard
|
|
|
|
|
|
|
|
The old configuration wizard has been replaced by res.config, but in order
|
|
|
|
not to break existing but not-yet-migrated addons, the old wizard was
|
|
|
|
reintegrated and gutted.
|
|
|
|
'''
|
|
|
|
_name='ir.actions.configuration.wizard'
|
|
|
|
_inherit = 'res.config'
|
|
|
|
|
|
|
|
def _next_action_note(self, cr, uid, ids, context=None):
|
|
|
|
next = self._next_action(cr, uid)
|
|
|
|
if next:
|
2009-12-17 14:19:14 +00:00
|
|
|
# if the next one is also an old-style extension, you never know...
|
|
|
|
if next.note:
|
|
|
|
return next.note
|
|
|
|
return "Click 'Continue' to configure the next addon..."
|
2009-12-16 15:59:41 +00:00
|
|
|
return "Your database is now fully configured.\n\n"\
|
|
|
|
"Click 'Continue' and enjoy your OpenERP experience..."
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'note': fields.text('Next Wizard', readonly=True),
|
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'note': _next_action_note,
|
|
|
|
}
|
|
|
|
|
|
|
|
def execute(self, cr, uid, ids, context=None):
|
|
|
|
self.logger.notifyChannel(
|
2009-12-17 14:19:35 +00:00
|
|
|
'configuration', netsvc.LOG_WARNING, DEPRECATION_MESSAGE)
|
|
|
|
|
2009-12-16 15:59:41 +00:00
|
|
|
ir_actions_configuration_wizard()
|
|
|
|
|
2009-12-03 15:11:22 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|