diff --git a/openerp/addons/base/res/__init__.py b/openerp/addons/base/res/__init__.py index 2b4da739f54..8bfaba2fe24 100644 --- a/openerp/addons/base/res/__init__.py +++ b/openerp/addons/base/res/__init__.py @@ -34,6 +34,7 @@ import res_request import res_lang import res_log import res_widget +import res_needaction import ir_property import wizard diff --git a/openerp/addons/base/res/res_needaction.py b/openerp/addons/base/res/res_needaction.py new file mode 100644 index 00000000000..529444b6e4e --- /dev/null +++ b/openerp/addons/base/res/res_needaction.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2009-Today OpenERP SA () +# +# 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 time +from osv import osv, fields +from tools.translate import _ + +class res_needaction(osv.osv): + '''Mixin class for object implementing a need_action mechanism + + Need action mechanism can be used by objects wanting to be able to + signal that an action is required on a particular record. If in the + business logic an action must be performed by somebody, for instance + validation by a manager, this mechanism allows to add have a field + linking to the user requested to perform the action. + + Technically, this class adds a need_action_user_id field; when + set to false, no action is required; when an user_id is set, + this user has an action to perform. Setting an user_id is done + through redefining the get_needaction_user_id method, that + stores the need_action_user_id function fields. + + This mechanism is used for instance to display the number of pending action + in menus. + ''' + _name = 'res.needaction' + _description = 'Need action Engine' + + def get_needaction_user_id(self, cr, uid, ids, name, arg, context=None): + if context is None: + context = {} + result = {} + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = False + return result + + ''' Wrapper: in 6.1 the reference to a method is given to a function + field, not the function name. Inheritance is therefore not directly + possible.''' + def get_needaction_user_id_wrapper(self, cr, uid, ids, name, arg, context=None): + return self.get_needaction_user_id(cr, uid, ids, name, arg, context=context) + + _columns = { + 'need_action_user_id': fields.function(get_needaction_user_id_wrapper, + type='many2one', relation='res.users', store=True, + select=1, string='User'), + } + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: