diff --git a/addons/idea/idea.py b/addons/idea/idea.py index d487c1875e7..270fdc87605 100644 --- a/addons/idea/idea.py +++ b/addons/idea/idea.py @@ -21,10 +21,12 @@ from osv import osv, fields -VoteValues = [('-1','Not Voted'),('0','Very Bad'),('25', 'Bad'),('50','Normal'),('75','Good'),('100','Very Good') ] +VoteValues = [('-1', 'Not Voted'), ('0', 'Very Bad'), ('25', 'Bad'), \ + ('50', 'Normal'), ('75', 'Good'), ('100', 'Very Good') ] DefaultVoteValue = '50' class idea_category(osv.osv): + """ Category of Idea """ _name = "idea.category" _description = "Category for an idea" _columns = { @@ -37,17 +39,20 @@ class idea_category(osv.osv): ('name', 'unique(parent_id,name)', 'The name of the category must be unique' ) ] _order = 'parent_id,name asc' + idea_category() + class idea_idea(osv.osv): _name = 'idea.idea' _rec_name = 'title' def _vote_avg_compute(self, cr, uid, ids, name, arg, context = None): - if not len(ids): + """ compute average for voting """ + if not ids: return {} - sql = """SELECT i.id, avg(v.score::integer) + sql = """SELECT i.id, avg(v.score::integer) FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id WHERE i.id = ANY(%s) GROUP BY i.id @@ -57,10 +62,11 @@ class idea_idea(osv.osv): return dict(cr.fetchall()) def _vote_count(self,cr,uid,ids,name,arg,context=None): - if not len(ids): + """ count number of vote """ + if not ids: return {} - sql = """SELECT i.id, COUNT(1) + sql = """SELECT i.id, COUNT(1) FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id WHERE i.id = ANY(%s) GROUP BY i.id @@ -70,10 +76,11 @@ class idea_idea(osv.osv): return dict(cr.fetchall()) def _comment_count(self,cr,uid,ids,name,arg,context=None): - if not len(ids): + """ count number of comment """ + if not ids: return {} - sql = """SELECT i.id, COUNT(1) + sql = """SELECT i.id, COUNT(1) FROM idea_idea i LEFT OUTER JOIN idea_comment c ON i.id = c.idea_id WHERE i.id = ANY(%s) GROUP BY i.id @@ -88,7 +95,8 @@ class idea_idea(osv.osv): res[id] = '-1' vote_obj = self.pool.get('idea.vote') votes_ids = vote_obj.search(cr, uid, [('idea_id', 'in', ids), ('user_id', '=', uid)]) - for vote in vote_obj.browse(cr, uid, votes_ids, context): + vote_obj_id = vote_obj.browse(cr, uid, votes_ids, context) + for vote in vote_obj_id: res[vote.idea_id.id] = vote.score return res @@ -98,12 +106,12 @@ class idea_idea(osv.osv): textual_value = str(field_value) if vote: if int(field_value)>=0: - vote_obj.write(cr,uid, vote, { 'score' : textual_value }) + vote_obj.write(cr,uid,vote,{'score': textual_value }) else: - vote_obj.unlink(cr,uid, vote) + vote_obj.unlink(cr,uid,vote) else: if int(field_value)>=0: - vote_obj.create(cr,uid, { 'idea_id' : id, 'user_id' : uid, 'score' : textual_value }) + vote_obj.create(cr,uid, {'idea_id': id,'user_id': uid,'score': textual_value }) _columns = { @@ -111,14 +119,14 @@ class idea_idea(osv.osv): 'title': fields.char('Idea Summary', size=64, required=True), 'description': fields.text('Description', required=True, help='Content of the idea'), 'comment_ids': fields.one2many('idea.comment', 'idea_id', 'Comments'), - 'create_date' : fields.datetime( 'Creation date', readonly=True), - 'vote_ids' : fields.one2many('idea.vote', 'idea_id', 'Vote'), - 'my_vote' : fields.function(_vote_read, fnct_inv = _vote_save, string="My Vote", method=True, type="selection", selection=VoteValues), - 'vote_avg' : fields.function(_vote_avg_compute, method=True, string="Average Score", type="float"), - 'count_votes' : fields.function(_vote_count, method=True, string="Count of votes", type="integer"), + 'create_date': fields.datetime( 'Creation date', readonly=True), + 'vote_ids': fields.one2many('idea.vote', 'idea_id', 'Vote'), + 'my_vote': fields.function(_vote_read, fnct_inv = _vote_save, string="My Vote", method=True, type="selection", selection=VoteValues), + 'vote_avg': fields.function(_vote_avg_compute, method=True, string="Average Score", type="float"), + 'count_votes': fields.function(_vote_count, method=True, string="Count of votes", type="integer"), 'count_comments': fields.function(_comment_count, method=True, string="Count of comments", type="integer"), 'category_id': fields.many2one('idea.category', 'Category', required=True ), - 'state': fields.selection([('draft','Draft'),('open','Opened'),('close','Accepted'),('cancel','Cancelled')], 'State', readonly=True, + 'state': fields.selection([('draft','Draft'),('open','Opened'),('close','Accepted'),('cancel','Cancelled')], 'State', readonly=True, help='When the Idea is created the state is \'Draft\'.\n It is opened by the user, the state is \'Opened\'.\ \nIf the idea is accepted, the state is \'Accepted\'.'), 'stat_vote_ids': fields.one2many('idea.vote.stat', 'idea_id', 'Statistics', readonly=True), @@ -132,31 +140,33 @@ class idea_idea(osv.osv): _order = 'id desc' def idea_cancel(self, cr, uid, ids): - self.write(cr, uid, ids, { 'state' : 'cancel' }) + self.write(cr, uid, ids, { 'state': 'cancel' }) return True def idea_open(self, cr, uid, ids): - self.write(cr, uid, ids, { 'state' : 'open' }) + self.write(cr, uid, ids, { 'state': 'open' }) return True def idea_close(self, cr, uid, ids): - self.write(cr, uid, ids, { 'state' : 'close' }) + self.write(cr, uid, ids, { 'state': 'close' }) return True def idea_draft(self, cr, uid, ids): - self.write(cr, uid, ids, { 'state' : 'draft' }) + self.write(cr, uid, ids, { 'state': 'draft' }) return True idea_idea() + class idea_comment(osv.osv): + """ Apply Idea for Comment """ _name = 'idea.comment' _description = 'Comments' _rec_name = 'content' _columns = { 'idea_id': fields.many2one('idea.idea', 'Idea', required=True, ondelete='cascade' ), 'user_id': fields.many2one('res.users', 'User', required=True ), - 'content': fields.text( 'Comment', required=True ), - 'create_date' : fields.datetime( 'Creation date', readonly=True), + 'content': fields.text('Comment', required=True ), + 'create_date' : fields.datetime('Creation date', readonly=True), } _defaults = { 'user_id': lambda self, cr, uid, context: uid @@ -164,8 +174,11 @@ class idea_comment(osv.osv): _order = 'id desc' idea_comment() + class idea_vote(osv.osv): + """ Apply Idea for Vote """ _name = 'idea.vote' + _description = 'Vote for Idea' _rec_name = 'score' _columns = { 'user_id': fields.many2one( 'res.users', 'User'), @@ -173,22 +186,24 @@ class idea_vote(osv.osv): 'score': fields.selection( VoteValues, 'Score', required=True) } _defaults = { - #'user_id': lambda self, cr, uid, context: uid, 'score': lambda *a: DefaultVoteValue, } idea_vote() + class idea_vote_stat(osv.osv): + """ Idea votes Statistics """ _name = 'idea.vote.stat' _description = 'Idea Votes Statistics' _auto = False _rec_name = 'idea_id' _columns = { 'idea_id': fields.many2one('idea.idea', 'Idea', readonly=True), - 'score': fields.selection( VoteValues, 'Score', readonly=True), + 'score': fields.selection(VoteValues, 'Score', readonly=True), 'nbr': fields.integer('Number of Votes', readonly=True), } - def init(self, cr): + + def init(self,cr): """ initialize the sql view for the stats @@ -207,6 +222,7 @@ class idea_vote_stat(osv.osv): GROUP BY i.id, v.score, i.id ) """) + idea_vote_stat() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/idea/idea_view.xml b/addons/idea/idea_view.xml index 9ccc56464d0..88c196b2e43 100644 --- a/addons/idea/idea_view.xml +++ b/addons/idea/idea_view.xml @@ -1,6 +1,9 @@ + + + idea.category.form @@ -34,9 +37,11 @@ - + - + + Ideas by Categories @@ -44,12 +49,15 @@ tree [('parent_id','=',False)] + + + Open Ideas @@ -66,6 +74,8 @@ + + idea.stat.form idea.stat @@ -79,6 +89,8 @@ + + idea.vote.tree idea.vote @@ -104,6 +116,8 @@ + + idea.idea.form idea.idea @@ -115,7 +129,6 @@ - @@ -171,6 +184,8 @@ + + idea.idea.search idea.idea @@ -180,8 +195,10 @@ - - + + @@ -191,6 +208,8 @@ + + idea.comment.tree idea.comment @@ -265,17 +284,19 @@ graph,tree - + - + - + Idea's vote idea.vote form tree,form + diff --git a/addons/idea/wizard/idea_post_vote.py b/addons/idea/wizard/idea_post_vote.py index 901f2c0a28d..858f85f214a 100644 --- a/addons/idea/wizard/idea_post_vote.py +++ b/addons/idea/wizard/idea_post_vote.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,24 +15,24 @@ # 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 . +# along with this program. If not, see . # ############################################################################## from osv import fields, osv class idea_post_vote(osv.osv_memory): - + _name = "idea.post.vote" _description = "Post vote" _columns = { - 'vote': fields.selection([('-1', 'Not Voted'), - ('0', 'Very Bad'), - ('25', 'Bad'), - ('50', 'Normal'), - ('75', 'Good'), + 'vote': fields.selection([('-1', 'Not Voted'), + ('0', 'Very Bad'), + ('25', 'Bad'), + ('50', 'Normal'), + ('75', 'Good'), ('100', 'Very Good') ], 'Post Vote', required=True) } - + def do_vote(self, cr, uid, ids, context): """ Create idea vote. @@ -41,10 +41,11 @@ class idea_post_vote(osv.osv_memory): @param ids: List of Idea Post vote’s IDs. @return: Dictionary {} """ + data = context and context.get('active_id', False) or False vote_obj = self.pool.get('idea.vote') - for data in self.read(cr, uid, ids): - score = str(data['vote']) - dic = {'idea_id': context['active_id'], 'user_id': uid, 'score': score } + for dovote_obj in self.read(cr, uid, ids): + score = str(dovote_obj['vote']) + dic = {'idea_id': data, 'user_id': uid, 'score': score } vote = vote_obj.create(cr, uid, dic) return {} diff --git a/addons/idea/wizard/idea_post_vote_view.xml b/addons/idea/wizard/idea_post_vote_view.xml index 7316340723c..fecefacba1f 100644 --- a/addons/idea/wizard/idea_post_vote_view.xml +++ b/addons/idea/wizard/idea_post_vote_view.xml @@ -1,6 +1,9 @@ + + + idea.post.vote.form idea.post.vote @@ -18,32 +21,22 @@ - + Vote idea.post.vote form tree,form - + new {'record_id':active_id} - - - + - - + +