[FIX] survey: display results of survey with no sections

Since commit https://github.com/odoo/odoo/commit/dba478332681dd21a39c4a183c002b1cf6e046d2, a survey can have questions with no section
associated, which means 'page_ids' field will be empty.

This prevents to display the analysis results of a survey, as we are
still expecting a structure page/questions. To solve it, if a question
does not have a section associated, we use an empty page instead.

closes odoo/odoo#39087

X-original-commit: 45c2964c1cfd07cabfa6a1a1b8e796bea4c521d7
Signed-off-by: Alex Tuyls <alt-odoo@users.noreply.github.com>
This commit is contained in:
alt-odoo
2019-10-21 07:40:07 +00:00
committed by fw-bot
parent c4d15475d9
commit db90ae1cd6
+17 -11
View File
@@ -560,19 +560,16 @@ class Survey(http.Controller):
def _prepare_result_dict(self, survey, current_filters=None):
"""Returns dictionary having values for rendering template"""
current_filters = current_filters if current_filters else []
Survey = request.env['survey.survey']
result = {'page_ids': []}
for page in survey.page_ids:
page_dict = {'page': page, 'question_ids': []}
for question in page.question_ids:
question_dict = {
'question': question,
'input_summary': Survey.get_input_summary(question, current_filters),
'prepare_result': Survey.prepare_result(question, current_filters),
'graph_data': self._get_graph_data(question, current_filters),
}
# First append questions without page
questions_without_page = [self._prepare_question_values(question,current_filters) for question in survey.question_ids if not question.page_id]
if questions_without_page:
result['page_ids'].append({'page': request.env['survey.question'], 'question_ids': questions_without_page})
page_dict['question_ids'].append(question_dict)
# Then, questions in sections
for page in survey.page_ids:
page_dict = {'page': page, 'question_ids': [self._prepare_question_values(question,current_filters) for question in page.question_ids]}
result['page_ids'].append(page_dict)
if survey.scoring_type in ['scoring_with_answers', 'scoring_without_answers']:
@@ -582,6 +579,15 @@ class Survey(http.Controller):
return result
def _prepare_question_values(self, question, current_filters):
Survey = request.env['survey.survey']
return {
'question': question,
'input_summary': Survey.get_input_summary(question, current_filters),
'prepare_result': Survey.prepare_result(question, current_filters),
'graph_data': self._get_graph_data(question, current_filters),
}
def _get_filter_data(self, post):
"""Returns data used for filtering the result"""
filters = []