[FIX] survey : use correct page_ids for progression template

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) <awa@odoo.com>
Signed-off-by: Joel Rodrigues Vitória (jorv) <jorv@odoo.com>
This commit is contained in:
jorv
2023-11-06 15:36:55 +00:00
parent 7dd22c9076
commit 02df60b307
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -38,7 +38,7 @@
<t t-set="page_number" t-value="page_ids.index(page.id) + (1 if survey.progression_mode == 'number' else 0)"/>
</t>
<t t-else="">
<t t-if="not answer.is_session_answer">
<t t-if="not answer.is_session_answer and survey.questions_selection == 'random'">
<t t-set="page_ids" t-value="answer.predefined_question_ids.ids"/>
</t>
<t t-else="">