[IMP]: idea: Usability Improvement in idea module.
[odoo/odoo.git] / addons / idea / wizard / idea_post_vote.py
index dac60dd..d09f3cd 100644 (file)
@@ -34,7 +34,7 @@ class idea_post_vote(osv.osv_memory):
                                           ('25', 'Bad'),
                                           ('50', 'Normal'),
                                           ('75', 'Good'),
-                                          ('100', 'Very Good') ], 'Post Vote', required=True),
+                                          ('100', 'Very Good') ], 'Give Vote', required=True),
                 'content': fields.text('Comment'),
                 }
     
@@ -48,25 +48,22 @@ class idea_post_vote(osv.osv_memory):
         @param context: A standard dictionary for contextual values
         """
         idea_obj = self.pool.get('idea.idea')
-       
         for idea in idea_obj.browse(cr, uid, context.get('active_ids', [])):
             
-            cr.execute('select count(id) from idea_vote where user_id=%s\
-                                                      and idea_id=%s' % (uid, context.get('active_id')))
-            res = cr.fetchone()[0]
-            user_limit = idea.vote_user
-            if  res >= user_limit:
+            for active_id in context.get('active_ids'):
+                cr.execute('select count(id) from idea_vote where user_id=%s\
+                                                      and idea_id=%s' % (uid, active_id))
+                res = cr.fetchone()[0]
+                user_limit = idea.vote_limit
+                if  res >= user_limit:
                    raise osv.except_osv(_('Warning !'),_("You can not give Vote for this idea more than %s times") % (user_limit))
         
-            if idea.state in ['draft', 'close', 'cancel']:
-                raise osv.except_osv(_("Warning !"), _("Draft/Accepted/Cancelled \
-ideas Could not be voted"))
             if idea.state != 'open':
-                raise osv.except_osv(_('Warning !'), _('idea should be in \
+                raise osv.except_osv(_('Warning !'), _('Idea should be in \
 \'Open\' state before vote for that idea.'))
         return False
 
-    def do_vote(self, cr, uid, ids, context):
+    def do_vote(self, cr, uid, ids, context=None):
 
         """
         Create idea vote.
@@ -75,21 +72,56 @@ ideas Could not be voted"))
         @param ids: List of Idea Post vote’s IDs.
         @return: Dictionary {}
         """
-        
-        data = context and context.get('active_id', False) or False
+        data = context and context.get('active_ids', []) or []
         vote_obj = self.pool.get('idea.vote')
-        comment_obj = self.pool.get('idea.comment')
-
         for do_vote_obj in self.read(cr, uid, ids):
             score = str(do_vote_obj['vote'])
             comment = do_vote_obj['content']
-            dic = {'idea_id': data, 'user_id': uid, 'score': score}
-            if comment:
-                comment_id = comment_obj.create(cr, uid, {'idea_id': data, 'user_id': uid, 'content': comment})
-            vote = vote_obj.create(cr, uid, dic)
+            for id in data:
+                dic = {'idea_id': id, 'user_id': uid, 'score': score, 'comment': comment}
+                vote = vote_obj.create(cr, uid, dic)
             return {}
-
+        
 idea_post_vote()
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+class idea_select(osv.osv_memory):
+    
+    """ Select idea for vote."""
+    
+    _name = "idea.select"
+    _description = "select idea"
 
+    _columns = {
+                'idea_id': fields.many2one('idea.idea', 'Idea', required=True),
+               }
+               
+    def open_vote(self, cr, uid, ids, context=None):
+       """ 
+       This function load column.
+       @param cr: the current row, from the database cursor,
+       @param uid: the current users ID for security checks,
+       @param ids: List of load column,
+       @return: dictionary of query logs clear message window
+       """
+       idea_obj = self.browse(cr, uid, ids)
+       for idea in idea_obj:
+           idea_id = idea.idea_id.id
+          
+       data_obj = self.pool.get('ir.model.data')
+       id2 = data_obj._get_id(cr, uid, 'idea', 'view_idea_post_vote')
+       if id2:
+            id2 = data_obj.browse(cr, uid, id2, context=context).res_id
+       value = {
+            'view_type': 'form', 
+            'view_mode': 'form', 
+            'res_model': 'idea.post.vote', 
+            'views': [(id2, 'form'), (False, 'tree'), (False, 'calendar'), (False, 'graph')], 
+            'type': 'ir.actions.act_window', 
+            'target': 'new',
+            'context': {'active_ids': [idea_id]}
+       }
+       return value
+    
+idea_select()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: