[FIX] ir.actions.todo: remove skip state, rename 'normal_recurring' to just 'recurrin...
authorXavier Morel <xmo@openerp.com>
Thu, 14 Jul 2011 10:38:07 +0000 (12:38 +0200)
committerXavier Morel <xmo@openerp.com>
Thu, 14 Jul 2011 10:38:07 +0000 (12:38 +0200)
bzr revid: xmo@openerp.com-20110714103807-1zlmg8f6f8lpw7el

openerp/addons/base/base_update.xml
openerp/addons/base/ir/ir_actions.py
openerp/addons/base/module/wizard/base_module_configuration.py
openerp/addons/base/res/res_config.py

index 1820c8d..06b8934 100644 (file)
             <field name="category_id" ref="category_administration_config"/>
             <field name="type">special</field>
             <field name="sequence">1</field>
-            <field name="state">skip</field>
         </record>
 
     </data>
index 4b271d6..eb24760 100644 (file)
@@ -163,13 +163,13 @@ class act_window(osv.osv):
 
     def _invalid_model_msg(self, cr, uid, ids, context=None):
         return _('Invalid model name in the action definition.')
-    
+
     _constraints = [
         (_check_model, _invalid_model_msg, ['res_model','src_model'])
     ]
 
     def _views_get_fnc(self, cr, uid, ids, name, arg, context=None):
-        """Returns an ordered list of the specific view modes that should be 
+        """Returns an ordered list of the specific view modes that should be
            enabled when displaying the result of this action, along with the
            ID of the specific view to use for each mode, if any were required.
 
@@ -209,7 +209,7 @@ class act_window(osv.osv):
             if act.search_view_id:
                 search_view_id = act.search_view_id.id
             else:
-                res_view = self.pool.get('ir.ui.view').search(cr, uid, 
+                res_view = self.pool.get('ir.ui.view').search(cr, uid,
                         [('model','=',act.res_model),('type','=','search'),
                         ('inherit_id','=',False)], context=context)
                 if res_view:
@@ -809,7 +809,7 @@ class ir_actions_todo_category(osv.osv):
     _name = 'ir.actions.todo.category'
     _description = "Configuration Wizard Category"
     _columns = {
-         'name':fields.char('Name', size=64, translate=True, required=True), 
+         'name':fields.char('Name', size=64, translate=True, required=True),
          'sequence': fields.integer('Sequence'),
          'wizards_ids': fields.one2many('ir.actions.todo', 'category_id', 'Configuration Wizards'),
     }
@@ -818,9 +818,10 @@ ir_actions_todo_category()
 # This model use to register action services.
 TODO_STATES = [('open', 'To Do'),
                ('done', 'Done'),
-               ('skip','Skipped'),
-               ('cancel','Cancelled')]
-
+               ('cancel', 'Cancelled')]
+TODO_TYPES = [('special', 'Special'),
+              ('normal', 'Normal'),
+              ('recurring', 'Recurring')]
 class ir_actions_todo(osv.osv):
     """
     Configuration Wizards
@@ -834,10 +835,10 @@ class ir_actions_todo(osv.osv):
         'sequence': fields.integer('Sequence'),
         'state': fields.selection(TODO_STATES, string='State', required=True),
         'name': fields.char('Name', size=64),
-        'type': fields.selection([('special','Special'),('normal','Normal'),('normal_recurring','Normal Recurring')], 'Type', required=True,
+        'type': fields.selection(TODO_TYPES, 'Type', required=True,
             help="""Special: the wizard is run whenever the system is reconfigured.
 Normal: the wizard is visible in the configuration panel until it is done.
-Normal Recurring: the wizard is visible in the configuration panel regardless of its state."""),
+Recurring: the wizard is visible in the configuration panel regardless of its state."""),
         'groups_id': fields.many2many('res.groups', 'res_groups_action_rel', 'uid', 'gid', 'Groups'),
         'note': fields.text('Text', translate=True),
         'category_id': fields.many2one('ir.actions.todo.category','Category'),
@@ -871,6 +872,43 @@ Normal Recurring: the wizard is visible in the configuration panel regardless of
         """ Sets configuration wizard in TODO state"""
         return self.write(cr, uid, ids, {'state': 'open'}, context=context)
 
+    def progress(self, cr, uid, context=None):
+        """ Returns a dict with 3 keys {todo, done, total}.
+
+        These keys all map to integers and provide the number of todos
+        marked as open, the total number of todos and the number of
+        todos not open (which is basically a shortcut to total-todo)
+
+        :rtype: dict
+        """
+        user_groups = set(map(
+            lambda x: x.id,
+            self.pool['res.users'].browse(cr, uid, [uid], context=context)[0].groups_id))
+        def groups_match(todo):
+            """ Checks if the todo's groups match those of the current user
+            """
+            return not todo.groups_id \
+                   or bool(user_groups.intersection((
+                        group.id for group in todo.groups_id)))
+
+        done = filter(
+            groups_match,
+            self.browse(cr, uid,
+                self.search(cr, uid, ['&', ('state', '!=', 'open'), ('type', '!=', 'special')], context=context),
+                        context=context))
+
+        total = filter(
+            groups_match,
+            self.browse(cr, uid,
+                self.search(cr, uid, [('type', '!=', 'special')], context=context),
+                        context=context))
+
+        return {
+            'done': len(done),
+            'total': len(total),
+            'todo': len(total) - len(done)
+        }
+
 ir_actions_todo()
 
 class act_client(osv.osv):
@@ -911,4 +949,3 @@ class act_client(osv.osv):
 act_client()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
index 2038873..f380232 100644 (file)
@@ -27,7 +27,8 @@ class base_module_configuration(osv.osv_memory):
     _name = "base.module.configuration"
 
     def start(self, cr, uid, ids, context=None):
-        todo_ids = self.pool.get('ir.actions.todo').search(cr, uid, ['|', '|', ('type','=','normal_recurring'), ('state', '=', 'open'), '&', ('state', '=', 'skip'), ('type', '=', 'special')])
+        todo_ids = self.pool.get('ir.actions.todo').search(cr, uid,
+            ['|', ('type','=','recurring'), ('state', '=', 'open')])
         if not todo_ids:
             # When there is no wizard todo it will display message
             data_obj = self.pool.get('ir.model.data')
index 24b4c67..2babfbf 100644 (file)
@@ -37,7 +37,6 @@ class res_config_configurable(osv.osv_memory):
     '''
     _name = 'res.config'
     _inherit = 'ir.wizard.screen'
-    logger = netsvc.Logger()
     __logger = logging.getLogger(_name)
 
     def get_current_progress(self, cr, uid, context=None):
@@ -45,7 +44,7 @@ class res_config_configurable(osv.osv_memory):
         a tuple of (non_open_todos:int, total_todos: int)
         '''
         todo_pool = self.pool.get('ir.actions.todo')
-        return (todo_pool.search_count(cr, uid, [('state','<>','open')], context),
+        return (todo_pool.search_count(cr, uid, [('state','!=','open')], context),
                 todo_pool.search_count(cr, uid, [], context))
 
     def _progress(self, cr, uid, context=None):
@@ -66,7 +65,7 @@ class res_config_configurable(osv.osv_memory):
         todos = self.pool.get('ir.actions.todo')
         self.__logger.info('getting next %s', todos)
         # Don't forget to change the domain in search view, if this condition is changed
-        active_todos = todos.search(cr, uid, [('state','=','open')],
+        active_todos = todos.search(cr, uid, ['|', ('type', '=', 'recurring'), ('state','=','open')],
                                     limit=1)
         if active_todos:
             todo_obj = todos.browse(cr, uid, active_todos[0], context=None)
@@ -119,7 +118,7 @@ class res_config_configurable(osv.osv_memory):
         todo_pool = self.pool.get('ir.actions.todo')
         ids2 = todo_pool.search(cr, uid, [], context=context)
         for todo in todo_pool.browse(cr, uid, ids2, context=context):
-            if (todo.type=='normal_recurring'):
+            if (todo.type=='recurring'):
                 todo.write({'state':'open'})
         return self.next(cr, uid, ids, context)