diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py
index ae27aa96719..fec8e04c4b7 100644
--- a/addons/gamification/models/challenge.py
+++ b/addons/gamification/models/challenge.py
@@ -387,6 +387,7 @@ class gamification_challenge(osv.Model):
end_date = challenge.end_date
for line in challenge.line_ids:
+ # FIXME: allow to restrict to a subset of users
for user in challenge.user_ids:
goal_obj = self.pool.get('gamification.goal')
@@ -400,8 +401,9 @@ class gamification_challenge(osv.Model):
# resume canceled goals
domain.append(('state', '=', 'canceled'))
canceled_goal_ids = goal_obj.search(cr, uid, domain, context=context)
- goal_obj.write(cr, uid, canceled_goal_ids, {'state': 'inprogress'}, context=context)
- goal_obj.update(cr, uid, canceled_goal_ids, context=context)
+ if canceled_goal_ids:
+ goal_obj.write(cr, uid, canceled_goal_ids, {'state': 'inprogress'}, context=context)
+ goal_obj.update(cr, uid, canceled_goal_ids, context=context)
# skip to next user
continue
@@ -516,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,
@@ -559,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/goal.py b/addons/gamification/models/goal.py
index 8792e219d71..8e79c43c8a6 100644
--- a/addons/gamification/models/goal.py
+++ b/addons/gamification/models/goal.py
@@ -163,7 +163,8 @@ class gamification_goal(osv.Model):
string="Challenge",
type='many2one',
relation='gamification.challenge',
- store=True),
+ store=True, readonly=True,
+ help="Challenge that generated the goal, assign challenge to users to generate goals with a value in this field."),
'start_date': fields.date('Start Date'),
'end_date': fields.date('End Date'), # no start and end = always active
'target_goal': fields.float('To Reach',
diff --git a/addons/gamification/models/res_users.py b/addons/gamification/models/res_users.py
index 408ddddf082..d25d725a4ac 100644
--- a/addons/gamification/models/res_users.py
+++ b/addons/gamification/models/res_users.py
@@ -42,6 +42,7 @@ class res_users_gamification_group(osv.Model):
challenge_ids = challenge_obj.search(cr, uid, [('autojoin_group_id', 'in', user_group_ids)], context=context)
if challenge_ids:
challenge_obj.write(cr, uid, challenge_ids, {'user_ids': [(4, user_id) for user_id in ids]}, context=context)
+ challenge_obj.generate_goals_from_challenge(cr, uid, challenge_ids, context=context)
return write_res
def create(self, cr, uid, vals, context=None):
@@ -56,6 +57,7 @@ class res_users_gamification_group(osv.Model):
challenge_ids = challenge_obj.search(cr, uid, [('autojoin_group_id', 'in', user_group_ids)], context=context)
if challenge_ids:
challenge_obj.write(cr, uid, challenge_ids, {'user_ids': [(4, write_res)]}, context=context)
+ challenge_obj.generate_goals_from_challenge(cr, uid, challenge_ids, context=context)
return write_res
# def get_goals_todo_info(self, cr, uid, context=None):
@@ -83,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
@@ -129,4 +133,5 @@ class res_groups_gamification_group(osv.Model):
challenge_ids = challenge_obj.search(cr, uid, [('autojoin_group_id', 'in', ids)], context=context)
if challenge_ids:
challenge_obj.write(cr, uid, challenge_ids, {'user_ids': [(4, user_id) for user_id in user_ids]}, context=context)
+ challenge_obj.generate_goals_from_challenge(cr, uid, challenge_ids, context=context)
return write_res
diff --git a/addons/gamification/views/goal.xml b/addons/gamification/views/goal.xml
index a269f710c02..1c408e3ab11 100644
--- a/addons/gamification/views/goal.xml
+++ b/addons/gamification/views/goal.xml
@@ -55,7 +55,7 @@
-
+
@@ -280,8 +280,8 @@
-
-
+
+
diff --git a/addons/hr_gamification/__openerp__.py b/addons/hr_gamification/__openerp__.py
index c75a4454437..14925421cb1 100644
--- a/addons/hr_gamification/__openerp__.py
+++ b/addons/hr_gamification/__openerp__.py
@@ -37,4 +37,5 @@ Badge received are displayed on the user profile.
'views/gamification.xml',
],
'js': ['static/src/js/gamification.js'],
+ 'auto_install': True,
}
diff --git a/addons/hr_gamification/views/gamification.xml b/addons/hr_gamification/views/gamification.xml
index e2d45948b95..60c758a717d 100644
--- a/addons/hr_gamification/views/gamification.xml
+++ b/addons/hr_gamification/views/gamification.xml
@@ -50,7 +50,7 @@
form
Goals History
tree,kanban
- {'search_default_group_by_user': True, 'search_default_group_by_type': True}
+ {'search_default_group_by_user': True, 'search_default_group_by_definition': True}
[('challenge_id.category', '=', 'hr')]