From bd9be9f061eb655c85751b2f2e8f6e561a6795a5 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Mon, 18 Jan 2021 08:36:49 +0000 Subject: [PATCH] [FW][FIX] survey: avoid retrospective computation - Create a survey with passing score at 80 point - Some user complete the quizz with 85 point, the quizz is "passed" - If you update the passing score at 90, the quizz completed by user are now "unpassed". This PR avoid to recompute quizz_passed. closes odoo/odoo#74238 X-original-commit: d5355037545fb8366675b792f8cc5ed30ecca1bf Signed-off-by: Thibault Delavallee (tde) --- addons/survey/models/survey_user.py | 2 +- addons/survey/tests/test_certification_flow.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/survey/models/survey_user.py b/addons/survey/models/survey_user.py index f9023a2b868..18b46250644 100644 --- a/addons/survey/models/survey_user.py +++ b/addons/survey/models/survey_user.py @@ -76,7 +76,7 @@ class SurveyUserInput(models.Model): score_percentage = (score_total / total_possible_score) * 100 user_input.scoring_percentage = round(score_percentage, 2) if score_percentage > 0 else 0 - @api.depends('scoring_percentage', 'survey_id.scoring_success_min') + @api.depends('scoring_percentage', 'survey_id') def _compute_scoring_success(self): for user_input in self: user_input.scoring_success = user_input.scoring_percentage >= user_input.survey_id.scoring_success_min diff --git a/addons/survey/tests/test_certification_flow.py b/addons/survey/tests/test_certification_flow.py index e76a0d629d3..367dff9211a 100644 --- a/addons/survey/tests/test_certification_flow.py +++ b/addons/survey/tests/test_certification_flow.py @@ -115,6 +115,10 @@ class TestCertificationFlow(common.TestSurveyCommon, HttpCase): self.assertEqual(user_inputs.scoring_percentage, 87.5) self.assertTrue(user_inputs.scoring_success) + # Check that the certification is still successful even if scoring_success_min of certification is modified + certification.write({'scoring_success_min': 90}) + self.assertTrue(user_inputs.scoring_success) + # Check answer correction is taken into account self.assertNotIn("I think they're great!", user_inputs.mapped('user_input_line_ids.value_text_box')) self.assertIn("Just kidding, I don't like it...", user_inputs.mapped('user_input_line_ids.value_text_box'))