diff options
| author | alt-odoo <alt@odoo.com> | 2019-10-17 08:01:47 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-10-21 07:40:07 +0000 |
| commit | db90ae1cd6b7417d17f0af076d9ec1987d94b509 (patch) | |
| tree | ac13d13240b7c2a0ec941c30983af6cf799197fe | |
| parent | c4d15475d95b98b3ddbebde7015c95a1989b9c34 (diff) | |
[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>
| -rw-r--r-- | addons/survey/controllers/main.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 75945503aa2..b9e3856d479 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -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': []} + + # 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}) + + # Then, questions in sections 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), - } - - page_dict['question_ids'].append(question_dict) + 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 = [] |
