From 1185f7b8b51da1e217d32b9018185ea5b7e3eab1 Mon Sep 17 00:00:00 2001 From: "Sunil Sharma (OpenERP)" Date: Fri, 21 Mar 2014 11:16:42 +0530 Subject: [PATCH] [imp]:improve gamification challenge line category forum and add clss gamification challenge assign reward user bzr revid: sunilsharma.sharma07@gmail.com-20140321054642-bjbgm4e92tur9f83 --- .../website_forum/data/forum_badges_data.xml | 68 +++++++++---------- addons/website_forum/models/website_forum.py | 33 +++++++++ 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/addons/website_forum/data/forum_badges_data.xml b/addons/website_forum/data/forum_badges_data.xml index a51dbd267ea..0bd852eac87 100644 --- a/addons/website_forum/data/forum_badges_data.xml +++ b/addons/website_forum/data/forum_badges_data.xml @@ -32,7 +32,7 @@ inprogress - other + forum @@ -65,7 +65,7 @@ inprogress - other + forum @@ -98,7 +98,7 @@ inprogress - other + forum @@ -131,7 +131,7 @@ inprogress - other + forum @@ -167,7 +167,7 @@ inprogress - other + forum @@ -200,7 +200,7 @@ inprogress - other + forum @@ -233,7 +233,7 @@ inprogress - other + forum @@ -275,7 +275,7 @@ result = get_counter(cr, uid, context=context) inprogress - other + forum @@ -317,7 +317,7 @@ result = get_counter(cr, uid, context=context) inprogress - other + forum @@ -350,7 +350,7 @@ result = get_counter(cr, uid, context=context) inprogress - other + forum @@ -365,7 +365,7 @@ result = get_counter(cr, uid, context=context) silver - + Favorite Question Ask a question which can be favorited by minimum 5 users @@ -392,7 +392,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -425,7 +425,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -458,7 +458,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -491,7 +491,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -524,7 +524,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -557,7 +557,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -601,7 +601,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -634,7 +634,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -667,7 +667,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -700,7 +700,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -733,7 +733,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -769,7 +769,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -802,7 +802,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -847,7 +847,7 @@ result = get_count(cr, uid, context=context) inprogress - other + forum @@ -881,7 +881,7 @@ result = get_count(cr, uid, context=context) inprogress - other + forum @@ -918,7 +918,7 @@ result = get_count(cr, uid, context=context) inprogress - other + forum @@ -933,7 +933,7 @@ result = get_count(cr, uid, context=context) bronze - + Stellar Question Ask a question which can be favorited by minimum 25 users @@ -960,7 +960,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -993,7 +993,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1026,7 +1026,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1059,7 +1059,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1092,7 +1092,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1125,7 +1125,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum diff --git a/addons/website_forum/models/website_forum.py b/addons/website_forum/models/website_forum.py index 683eb0902d7..db14cd32a7e 100644 --- a/addons/website_forum/models/website_forum.py +++ b/addons/website_forum/models/website_forum.py @@ -353,3 +353,36 @@ class Tags(osv.Model): } ), } + +class gamification_challenge(osv.Model): + _inherit = 'gamification.challenge' + + def _get_categories(self, cr, uid, context=None): + res = super(gamification_challenge, self)._get_categories(cr, uid, + context=context) + res.append(('forum', 'Website / Q.A')) + return res + + _columns = { + 'category': fields.selection(lambda s, *a, **k: s._get_categories(*a, **k), + string="Appears in", help="Define the visibility of the challenge through menus", required=True), + } + + def check_challenge_reward(self, cr, uid, ids, force=False, context=None): + if isinstance(ids, (int,long)): + ids = [ids] + context = context or {} + badge_user_obj = self.pool.get('gamification.badge.user'); + for challenge in self.browse(cr, uid, ids, context=context): + if challenge.category == 'forum': + for user in challenge.user_ids: + bages_user_ids = badge_user_obj.search(cr, uid, [('user_id', '=', user.id),('badge_id', '=', challenge.reward_id.id)],context=None) + if not bages_user_ids: + reached_goal_ids = self.pool.get('gamification.goal').search(cr, uid, [ + ('challenge_id', '=', challenge.id), + ('user_id', '=', user.id), + ('state', '=', 'reached'), + ], context=context) + if len(reached_goal_ids) == len(challenge.line_ids): + super(gamification_challenge, self).check_challenge_reward(cr, uid, ids, force=False, context=context) + self.reward_user(cr, uid, user.id, challenge.reward_id.id, context)