From 02df60b3075c62ca4d1e46f38f157ca0544fd8a8 Mon Sep 17 00:00:00 2001 From: jorv Date: Mon, 16 Oct 2023 09:02:43 +0200 Subject: [PATCH] [FIX] survey : use correct page_ids for progression template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug A previous commit b1ec81ed fixed an issue relating to wrong progression percentages when a survey was set as "one page per question" and "random selection". In doing so, it inadvertently added an issue in the following simplified case: 1. Create a new survey, and add 2 questions 2. Set layout (`question_layout`) to "one page per question" (`page_per_question`) 3. Set selection (`question_selection`) to "all questions" (`all`) 4. Now share the survey with a participant (send out the email) 5. As the participant, start the survey and answer question one 6. In the backend, go and modify the survey template by adding a new question after question 2. Save modification. 7. Now, in the ongoing survey, answer question 2 and try to move on to the next question. This will create an error traceback. Example ''' 'page_number': page_ids.index(survey_data['question'].id) ValueError: 108 is not in list ''' The error arises because the added question will have an id that is not in the `survey.user_input.predefined_question_ids` field. This list gets initialized when the `survey.user_input` gets created and reflects all the question ids of the original survey template (or the random ids in case of a random selection). So in other terms the set of questions given to a participant, starting in `survey_survey._get_pages_or_questions` is not aligned with those used for the references in the progression template Proposed fix: We add an extra check for `survey_sudo.questions_selection == 'random'` to decide if we use `survey.user_input.predefined_question_ids` or `survey.survey.question_ids` information to calculate the progession. opw-3516304 closes odoo/odoo#141171 X-original-commit: 643fceff43770483f11e95bd57fae60e611f83d4 Signed-off-by: Warnon Aurélien (awa) Signed-off-by: Joel Rodrigues Vitória (jorv) --- addons/survey/controllers/main.py | 2 +- addons/survey/views/survey_templates.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 0e6f516c3dc..30bddc36129 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -370,7 +370,7 @@ class Survey(http.Controller): }) elif survey_sudo.questions_layout == 'page_per_question': page_ids = (answer_sudo.predefined_question_ids.ids - if not answer_sudo.is_session_answer + if not answer_sudo.is_session_answer and survey_sudo.questions_selection == 'random' else survey_sudo.question_ids.ids) survey_progress = request.env['ir.qweb']._render('survey.survey_progression', { 'survey': survey_sudo, diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 9d95b178069..8600876f89f 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -38,7 +38,7 @@ - +