[FIX] survey: display only answered question in survey review mode

Unanswered questions or sections are now hidden in the survey review mode.
Only the question answered by the user will be visible.
If the survey was done during a session, the users will see their own answers,
even if the theme they selected was not the most voted one (in case of
conditional questions).

To get the questions to display :
- questions that have been answered
- + the ones that should have been answered = active questions
  In session, active questions are based on most voted answers)

This commit also fixes the randomized questions handling in most voted answers,
as copied predefined questions where <NewIds> and those was not usable in
some templates.

Task ID: 2230980

X-original-commit: 8ca79727d5a93b91746c1e63d59d08550417906c
This commit is contained in:
David Beguin
2020-07-28 08:03:34 +00:00
committed by Thibault Delavallée
parent 2efc4678bc
commit f0f7f888d3
4 changed files with 28 additions and 8 deletions
+3 -1
View File
@@ -552,12 +552,14 @@ class Survey(http.Controller):
return request.render("survey.survey_403_page", {'survey': survey_sudo})
return request.render('survey.survey_page_print', {
'is_html_empty': is_html_empty,
'review': review,
'survey': survey_sudo,
'answer': answer_sudo,
'questions_to_display': answer_sudo._get_print_questions(),
'scoring_display_correction': survey_sudo.scoring_type == 'scoring_with_answers' and answer_sudo,
'format_datetime': lambda dt: format_datetime(request.env, dt, dt_format=False),
'format_date': lambda date: format_date(request.env, date)
'format_date': lambda date: format_date(request.env, date),
})
@http.route(['/survey/<model("survey.survey"):survey>/get_certification_preview'], type="http", auth="user", methods=['GET'], website=True)
+2 -1
View File
@@ -726,9 +726,10 @@ class Survey(models.Model):
if not most_voted_answer or votes_by_answer[most_voted_answer] < votes_by_answer[answer]:
most_voted_answer_by_questions[question] = answer
# return a fake 'audiance' user_input
# return a fake 'audience' user_input
fake_user_input = self.env['survey.user_input'].new({
'survey_id': self.id,
'predefined_question_ids': [(6, 0, self._prepare_user_input_predefined_questions().ids)]
})
fake_user_input_lines = self.env['survey.user_input.line']
+13
View File
@@ -461,6 +461,19 @@ class SurveyUserInput(models.Model):
inactive_questions |= question
return inactive_questions
def _get_print_questions(self):
""" Get the questions to display : the ones that should have been answered = active questions
In case of session, active questions are based on most voted answers
:return: active survey.question browse records
"""
survey = self.survey_id
if self.is_session_answer:
most_voted_answers = survey._get_session_most_voted_answers()
inactive_questions = most_voted_answers._get_inactive_conditional_questions()
else:
inactive_questions = self._get_inactive_conditional_questions()
return survey.question_ids - inactive_questions
class SurveyUserInputLine(models.Model):
_name = 'survey.user_input.line'
+10 -6
View File
@@ -16,12 +16,16 @@
<div role="form">
<fieldset disabled="disabled">
<t t-foreach='survey.question_and_page_ids' t-as='question'>
<hr t-if="question.is_page and question != survey.page_ids[0]" />
<div t-if="question.is_page" class="o_page_header">
<h1 t-field='question.title' />
<div t-if="question.description" t-field='question.description' class="oe_no_empty"/>
</div>
<t t-if="not question.is_page and not answer or (question in answer.predefined_question_ids)" >
<t t-if="question.is_page and
(any(q in questions_to_display for q in question.question_ids)
or not is_html_empty(question.description))">
<hr t-if="question != survey.page_ids[0]" />
<div class="o_page_header">
<h1 t-field='question.title' />
<div t-if="question.description" t-field='question.description' class="oe_no_empty"/>
</div>
</t>
<t t-if="not question.is_page and not answer or (question in answer.predefined_question_ids &amp; questions_to_display)" >
<t t-set="answer_lines" t-value="answer.user_input_line_ids.filtered(lambda line: line.question_id == question)"/>
<div class="js_question-wrapper" t-att-id="question.id">
<h2>