[FIX] gamification: Goal definition "sum"

Steps:
- Open Settings/Gamification Tools/Challenges
- Create a new challenge
    - Keep "Assign Challenge to" with default values
    - Need a domain that return some user
- Create and Edit a goal
    - Computation Mode: "Automatic: sum on a field"
    - Save & Close
- In reward Tab set "For Every Succeeding User"
- Save
- Start Challenge

Actual result:
- Traceback due to wrong aggregate value
- CHallenge is not started

Expected result:
- Challenge is started

opw-3740960

odoo/odoo@234db70d

closes odoo/odoo#154614

X-original-commit: aa0f617682a59c5ac285308000f35d44b75f04df
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
Gaetan Vanden Bergh (gavb)
2024-02-19 17:53:15 +00:00
parent 43d8a470e4
commit 5f51ed9ad9
2 changed files with 34 additions and 1 deletions
@@ -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
@@ -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):