diff --git a/addons/gamification/models/gamification_goal.py b/addons/gamification/models/gamification_goal.py index e8997ebddc1..55343a0f77e 100644 --- a/addons/gamification/models/gamification_goal.py +++ b/addons/gamification/models/gamification_goal.py @@ -211,7 +211,7 @@ class Goal(models.Model): if definition.computation_mode == 'sum': field_name = definition.field_id.name - res = Obj._read_group(domain, [], [field_name]) + res = Obj._read_group(domain, [], [f'{field_name}:{definition.computation_mode}']) new_value = res[0][0] or 0.0 else: # computation mode = count diff --git a/addons/gamification/tests/test_challenge.py b/addons/gamification/tests/test_challenge.py index de0cc5f582d..ac3d1abd10e 100644 --- a/addons/gamification/tests/test_challenge.py +++ b/addons/gamification/tests/test_challenge.py @@ -151,6 +151,39 @@ class test_challenge(TestGamificationCommon): unchanged_goal_ids.user_id, ) + def test_30_create_challenge_with_sum_goal(self): + challenge = self.env['gamification.challenge'].create({ + 'name': 'test', + 'state': 'draft', + 'user_domain': '[("active", "=", True)]', #Include all active users to get a least one participant + 'reward_id': 1, + }) + + model = self.env['ir.model'].search([('model', '=', 'gamification.badge')])[0] + field = self.env['ir.model.fields'].search([('model', '=', 'gamification.badge'), ('name', '=', 'rule_max_number')])[0] + + sum_goal = self.env['gamification.goal.definition'].create({ + 'name': 'test', + 'computation_mode': 'sum', + 'model_id': model.id, + 'field_id': field.id + }) + + self.env['gamification.challenge.line'].create({ + 'challenge_id': challenge.id, + 'definition_id': sum_goal.id, + 'condition': 'higher', + 'target_goal': 1 + }) + + challenge.action_start() + + self.assertEqual( + challenge.state, + 'inprogress', + "Challenge failed to start", + ) + class test_badge_wizard(TestGamificationCommon):