diff --git a/addons/website_forum/data/forum_badges_data.xml b/addons/website_forum/data/forum_badges_data.xml index a51dbd267ea..71387fe96fc 100644 --- a/addons/website_forum/data/forum_badges_data.xml +++ b/addons/website_forum/data/forum_badges_data.xml @@ -2,7 +2,6 @@ - Autobiographer @@ -32,7 +31,7 @@ inprogress - other + forum @@ -65,7 +64,7 @@ inprogress - other + forum @@ -98,7 +97,7 @@ inprogress - other + forum @@ -131,7 +130,7 @@ inprogress - other + forum @@ -167,7 +166,7 @@ inprogress - other + forum @@ -200,7 +199,7 @@ inprogress - other + forum @@ -233,7 +232,7 @@ inprogress - other + forum @@ -275,7 +274,7 @@ result = get_counter(cr, uid, context=context) inprogress - other + forum @@ -317,7 +316,7 @@ result = get_counter(cr, uid, context=context) inprogress - other + forum @@ -350,7 +349,7 @@ result = get_counter(cr, uid, context=context) inprogress - other + forum @@ -365,7 +364,7 @@ result = get_counter(cr, uid, context=context) silver - + Favorite Question Ask a question which can be favorited by minimum 5 users @@ -392,7 +391,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -425,7 +424,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -458,7 +457,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -491,7 +490,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -524,7 +523,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -557,7 +556,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -601,12 +600,12 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum - 1 + 2 @@ -634,7 +633,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -667,7 +666,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -700,7 +699,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -733,7 +732,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -752,24 +751,24 @@ result = get_posts(cr, uid, context=context) it should shange boolean field?. at this time we are showing post with 3 down vote(not deleted) --> - Discipline - Delete own post with 3 or more upvotes + Peer Pressure + Delete own post with 3 or more down votes count boolean - [('user_id','=',user.id), ('vote_count', '>=', -3)] + [('user_id','=',user.id), ('vote_count', '<=', -3)] higher - Disciplined + Peer Pressure once personal never inprogress - other + forum @@ -802,7 +801,7 @@ result = get_posts(cr, uid, context=context) inprogress - other + forum @@ -847,7 +846,7 @@ result = get_count(cr, uid, context=context) inprogress - other + forum @@ -881,7 +880,7 @@ result = get_count(cr, uid, context=context) inprogress - other + forum @@ -918,7 +917,7 @@ result = get_count(cr, uid, context=context) inprogress - other + forum @@ -933,7 +932,7 @@ result = get_count(cr, uid, context=context) bronze - + Stellar Question Ask a question which can be favorited by minimum 25 users @@ -960,7 +959,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -993,7 +992,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1026,7 +1025,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1059,7 +1058,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1092,7 +1091,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum @@ -1125,7 +1124,7 @@ result = count_favorites(cr, uid, context=context) inprogress - other + forum diff --git a/addons/website_forum/models/__init__.py b/addons/website_forum/models/__init__.py index 510e6b63aa0..15f26e908cd 100644 --- a/addons/website_forum/models/__init__.py +++ b/addons/website_forum/models/__init__.py @@ -19,4 +19,5 @@ # ############################################################################## -import website_forum +import gamification +import forum diff --git a/addons/website_forum/models/website_forum.py b/addons/website_forum/models/forum.py similarity index 98% rename from addons/website_forum/models/website_forum.py rename to addons/website_forum/models/forum.py index ed25cbb42b1..0f19f08f2ec 100644 --- a/addons/website_forum/models/website_forum.py +++ b/addons/website_forum/models/forum.py @@ -316,12 +316,6 @@ class Vote(osv.Model): post.refresh() return {'vote_count': post.vote_count} -class Badge(osv.Model): - _inherit = 'gamification.badge' - _columns = { - 'level': fields.selection([('bronze', 'bronze'), ('silver', 'silver'), ('gold', 'gold')], 'Forum Badge Level'), - } - class MailMessage(osv.Model): _inherit = 'mail.message' _columns = { diff --git a/addons/website_forum/models/gamification.py b/addons/website_forum/models/gamification.py new file mode 100644 index 00000000000..f29b5985aa9 --- /dev/null +++ b/addons/website_forum/models/gamification.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# 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 . +# +############################################################################## + +import openerp +from openerp.osv import osv, fields +from openerp.tools.translate import _ + +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 / Forum')) + 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): + """NOTE: gamification module never assigns reward for and on going challenge, + here we need to assign badges to the users who have completed their goal.""" + if isinstance(ids, (int,long)): + ids = [ids] + context = context or {} + badge_user_obj = self.pool.get('gamification.badge.user'); + super(gamification_challenge, self).check_challenge_reward(cr, uid, ids, force=False, context=context) + for challenge in self.browse(cr, uid, ids, context=context): + if challenge.category == 'forum': + rewarded_users = [] + 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 user not rewarded before then give reward. + 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): + self.reward_user(cr, uid, user.id, challenge.reward_id.id, context) + rewarded_users.append(user) + if rewarded_users: + message_body = _("Reward (badge %s) for every succeeding user was sent to %s." % (challenge.reward_id.name, ", ".join([user.name for user in rewarded_users]))) + self.message_post(cr, uid, challenge.id, body=message_body, context=context) + return True + +class Badge(osv.Model): + _inherit = 'gamification.badge' + _columns = { + 'level': fields.selection([('bronze', 'bronze'), ('silver', 'silver'), ('gold', 'gold')], 'Forum Badge Level'), + } +