diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index ce940df1fa5..fec8e04c4b7 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -518,13 +518,6 @@ class gamification_challenge(osv.Model): domain.append(('user_id', '=', user_id)) sorting = goal_obj._order limit = 1 - # initialise in case search returns no results - line_data.update({ - 'id': 0, - 'current': 0, - 'completeness': 0, - 'state': 'draft', - }) else: line_data.update({ 'own_goal_id': False, @@ -561,7 +554,8 @@ class gamification_challenge(osv.Model): 'completeness': goal.completeness, 'state': goal.state, }) - res_lines.append(line_data) + if goal_ids: + res_lines.append(line_data) return res_lines ##### Reporting ##### diff --git a/addons/gamification/models/res_users.py b/addons/gamification/models/res_users.py index b58a65a877d..d25d725a4ac 100644 --- a/addons/gamification/models/res_users.py +++ b/addons/gamification/models/res_users.py @@ -85,13 +85,15 @@ class res_users_gamification_group(osv.Model): challenge_ids = challenge_obj.search(cr, uid, [('user_ids', 'in', uid), ('state', '=', 'inprogress')], context=context) for challenge in challenge_obj.browse(cr, uid, challenge_ids, context=context): # serialize goals info to be able to use it in javascript - all_goals_info.append({ - 'id': challenge.id, - 'name': challenge.name, - 'visibility_mode': challenge.visibility_mode, - 'currency': user.company_id.currency_id.id, - 'lines': challenge_obj._get_serialized_challenge_lines(cr, uid, challenge, user_id, restrict_top=MAX_VISIBILITY_RANKING, context=context), - }) + lines = challenge_obj._get_serialized_challenge_lines(cr, uid, challenge, user_id, restrict_top=MAX_VISIBILITY_RANKING, context=context) + if lines: + all_goals_info.append({ + 'id': challenge.id, + 'name': challenge.name, + 'visibility_mode': challenge.visibility_mode, + 'currency': user.company_id.currency_id.id, + 'lines': lines, + }) return all_goals_info