1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import osv, fields
25 class res_config_configurable(osv.osv_memory):
26 ''' Base classes for new-style configuration items
28 Configuration items should inherit from this class, implement
29 the execute method (and optionally the cancel one) and have
30 their view inherit from the related res_config_view_base view.
33 logger = netsvc.Logger()
35 def _progress(self, cr, uid, context=None):
36 total = self.pool.get('ir.actions.todo')\
37 .search_count(cr, uid, [], context)
38 open = self.pool.get('ir.actions.todo')\
39 .search_count(cr, uid, [('active','=',True),
40 ('state','<>','open')],
43 return round(open*100./total)
47 progress=fields.float('Configuration Progress', readonly=True),
53 def _next_action(self, cr, uid):
54 todos = self.pool.get('ir.actions.todo')
55 self.logger.notifyChannel('actions', netsvc.LOG_INFO,
56 'getting next %s' % todos)
57 active_todos = todos.search(cr, uid, [('state','=','open'),
59 limit=1, context=None)
61 return todos.browse(cr, uid, active_todos[0], context=None)
64 def _next(self, cr, uid):
65 self.logger.notifyChannel('actions', netsvc.LOG_INFO,
66 'getting next operation')
67 next = self._next_action(cr, uid)
68 self.logger.notifyChannel('actions', netsvc.LOG_INFO,
69 'next action is %s' % next)
71 self.pool.get('ir.actions.todo').write(cr, uid, next.id, {
74 action = next.action_id
76 'view_mode': action.view_mode,
77 'view_type': action.view_type,
78 'view_id': action.view_id and [action.view_id.id] or False,
79 'res_model': action.res_model,
81 'target': action.target,
83 self.logger.notifyChannel(
84 'actions', netsvc.LOG_INFO,
85 'all configuration actions have been executed')
87 current_user_menu = self.pool.get('res.users')\
88 .browse(cr, uid, uid).menu_id
89 # return the action associated with the menu
90 return self.pool.get(current_user_menu.type)\
91 .read(cr, uid, current_user_menu.id)
92 def next(self, cr, uid, ids, context=None):
93 return self._next(cr, uid)
95 def execute(self, cr, uid, ids, context=None):
96 raise NotImplementedError(
97 'Configuration items need to implement execute')
98 def cancel(self, cr, uid, ids, context=None):
101 def action_next(self, cr, uid, ids, context=None):
102 next = self.execute(cr, uid, ids, context=None)
104 return self.next(cr, uid, ids, context=context)
106 def action_skip(self, cr, uid, ids, context=None):
107 next = self.cancel(cr, uid, ids, context=None)
109 return self.next(cr, uid, ids, context=context)
110 res_config_configurable()
112 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: