From 1b85f20ca566e2a0741ee28ee4efb580b9b1b54c Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Tue, 13 Apr 2010 18:51:45 +0530 Subject: [PATCH] [IMP]: idea: Add view_init method in idea post vote wizard for user cannot votes draft/close ideas bzr revid: atp@tinyerp.co.in-20100413132145-trcfsu8xkjgzgm6p --- addons/idea/wizard/idea_post_vote.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/addons/idea/wizard/idea_post_vote.py b/addons/idea/wizard/idea_post_vote.py index f76dd1aa562..c5e6c530334 100644 --- a/addons/idea/wizard/idea_post_vote.py +++ b/addons/idea/wizard/idea_post_vote.py @@ -20,6 +20,7 @@ ############################################################################## from osv import fields, osv +from tools.translate import _ class idea_post_vote(osv.osv_memory): """ Post Vote For Idea """ @@ -35,6 +36,27 @@ class idea_post_vote(osv.osv_memory): ('75', 'Good'), ('100', 'Very Good') ], 'Post Vote', required=True) } + + def view_init(self, cr, uid, fields, context=None): + """ + This function checks for precondition before wizard executes + @param self: The object pointer + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID for security checks, + @param fields: List of fields for default value + @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', [])): + 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 \ +\'Open\' state before vote for that idea.')) + return False + def do_vote(self, cr, uid, ids, context): @@ -52,6 +74,7 @@ class idea_post_vote(osv.osv_memory): for do_vote_obj in self.read(cr, uid, ids): score = str(do_vote_obj['vote']) dic = {'idea_id': data, 'user_id': uid, 'score': score } + vote = vote_obj.create(cr, uid, dic) return {}