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
|
|
|
|
|
|
|
|
class res_config_configurable(osv.osv_memory):
|
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')
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
|
|
|
def next(self, cr, uid, *args, **kwargs):
|
|
|
|
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
|
|
|
|
return self._next(cr, uid)
|
|
|
|
|
|
|
|
def action_skip(self, cr, uid, ids, context=None):
|
|
|
|
next = self.cancel(cr, uid, ids, context=None)
|
|
|
|
if next: return next
|
2009-12-08 13:19:47 +00:00
|
|
|
return self._next(cr, uid)
|
2009-12-03 15:11:22 +00:00
|
|
|
res_config_configurable()
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|