# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2009-Today OpenERP SA (<http://www.openerp.com>)
#
#    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/>
#
##############################################################################

from osv import osv, fields

class ir_needaction_mixin(osv.Model):
    '''Mixin class for objects using the need action feature.

    Need action feature can be used by objects having 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 set a
    list of users asked to perform an action.

    Objects using the 'need_action' feature should override the
    ``needaction_domain_get`` method. This methods returns a
    domain to filter records requiring an action for a specific user.

    This class also offers several global services:
    - ``needaction_get_action_count``: as ``needaction_get_record_ids``
    but returns only the number of action, not the ids (performs a
    search with count=True)
    '''

    _name = 'ir.needaction_mixin'
    _description = 'Need Action Mixin'
    _needaction = True

    #------------------------------------------------------
    # Addon API
    #------------------------------------------------------

    def _needaction_domain_get(self, cr, uid, context=None):
        """ Returns the domain to filter records that require an action
            :return: domain or False is no need action
        """
        return False

    #------------------------------------------------------
    # "Need action" API
    #------------------------------------------------------

    def _needaction_count(self, cr, uid, domain=[], context=None):
        """Given the current model and a user_id
           get the number of actions it has to perform"""
        dom = self._needaction_domain_get(cr, uid, context=context)
        return self.search(cr, uid, domain+dom, context=context, count=True)


@@ -1847,112 +1847,1314 @@
 ue)%0A
-    '''%0A%0A    _name = 'ir.needaction_mixin'%0A    _description = 'Need Action Mixin'%0A    _needaction = True
+%0A    The %60%60ir_needaction_mixin%60%60 class adds a calculated field%0A    %60%60needaction_pending%60%60. This function field allows to state%0A    whether a given record has a needaction for the current user.%0A    This is usefull if you want to customize views according to the%0A    needaction feature. For example, you may want to set records in%0A    bold in a list view if the current user has an action to perform%0A    on the record.%0A    '''%0A%0A    _name = 'ir.needaction_mixin'%0A    _description = 'Need Action Mixin'%0A    _needaction = True%0A%0A   def get_needaction_pending(self, cr, uid, ids, name, arg, context=None):%0A       dom = self._needaction_domain_get(cr, uid, context=context)%0A       result = dict.fromkeys(ids, False)%0A       ids2 = self.search(cr, uid, %5B('id','in',ids)+dom%5D, context=context)%0A       for idna in ids2:%0A           result%5Bidna%5D = True%0A       return result%0A%0A    def search_needaction_pending(self, cr, uid, field, field_name, criterion, context=None):%0A        return self._needaction_domain_get(cr, uid, context=context)%0A%0A    _columns = %7B%0A        'needaction_pending': fields.function(%0A            get_needaction_pending, type='boolean',%0A            fnct_search=search_needaction_pending,%0A            string='Need an Action',%0A            help=%22Do the current user requires to perform an action.%22),%0A    %7D
 %0A%0A  

put needaction_pending again, new implementation