diff --git a/addons/survey/models/survey_user_input.py b/addons/survey/models/survey_user_input.py index e6aab8ba70a..93e86ccb7c6 100644 --- a/addons/survey/models/survey_user_input.py +++ b/addons/survey/models/survey_user_input.py @@ -63,7 +63,9 @@ class SurveyUserInput(models.Model): # sum(multi-choice question scores) + sum(simple answer_type scores) total_possible_score = 0 for question in user_input.predefined_question_ids: - if question.question_type in ['simple_choice', 'multiple_choice']: + if question.question_type == 'simple_choice': + total_possible_score += max([score for score in question.mapped('suggested_answer_ids.answer_score') if score > 0], default=0) + elif question.question_type == 'multiple_choice': total_possible_score += sum(score for score in question.mapped('suggested_answer_ids.answer_score') if score > 0) elif question.is_scored_question: total_possible_score += question.answer_score diff --git a/addons/survey/tests/test_survey.py b/addons/survey/tests/test_survey.py index dc6469b1f56..7494e528eed 100644 --- a/addons/survey/tests/test_survey.py +++ b/addons/survey/tests/test_survey.py @@ -104,6 +104,46 @@ class TestSurveyInternals(common.TestSurveyCommon): {} ) + def test_partial_scores_simple_choice(self): + """" Check that if partial scores are given for partially correct answers, in the case of a multiple + choice question with single choice, choosing the answer with max score gives 100% of points. """ + + partial_scores_survey = self.env['survey.survey'].create({ + 'title': 'How much do you know about words?', + 'scoring_type': 'scoring_with_answers', + 'scoring_success_min': 90.0, + }) + [a_01, a_02, a_03] = self.env['survey.question.answer'].create([{ + 'value': 'A thing full of letters.', + 'answer_score': 1.0 + }, { + 'value': 'A unit of language, [...], carrying a meaning.', + 'answer_score': 4.0, + 'is_correct': True + }, { + 'value': '42', + 'answer_score': -4.0 + }]) + q_01 = self.env['survey.question'].create({ + 'survey_id': partial_scores_survey.id, + 'title': 'What is a word?', + 'sequence': 1, + 'question_type': 'simple_choice', + 'suggested_answer_ids': [(6, 0, (a_01 | a_02 | a_03).ids)] + }) + + user_input = self.env['survey.user_input'].create({'survey_id': partial_scores_survey.id}) + self.env['survey.user_input.line'].create({ + 'user_input_id': user_input.id, + 'question_id': q_01.id, + 'answer_type': 'suggestion', + 'suggested_answer_id': a_02.id + }) + + # Check that scoring is correct and survey is passed + self.assertEqual(user_input.scoring_percentage, 100) + self.assertTrue(user_input.scoring_success) + @users('survey_manager') def test_skipped_values(self): """ Create one question per type of questions.