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 class ir_actions_configuration_wizard(osv.osv_memory):
113 ''' Compatibility configuration wizard
115 The old configuration wizard has been replaced by res.config, but in order
116 not to break existing but not-yet-migrated addons, the old wizard was
117 reintegrated and gutted.
119 _name='ir.actions.configuration.wizard'
120 _inherit = 'res.config'
122 def _next_action_note(self, cr, uid, ids, context=None):
123 next = self._next_action(cr, uid)
125 # if the next one is also an old-style extension, you never know...
128 return "Click 'Continue' to configure the next addon..."
129 return "Your database is now fully configured.\n\n"\
130 "Click 'Continue' and enjoy your OpenERP experience..."
133 'note': fields.text('Next Wizard', readonly=True),
136 'note': _next_action_note,
139 def execute(self, cr, uid, ids, context=None):
140 self.logger.notifyChannel(
141 'configuration', netsvc.LOG_WARNING,
142 'Addon using old-style configuration wizard, please migrate to '\
143 'res.config objects')
144 ir_actions_configuration_wizard()
146 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: