From 7c8cb23aae11a184b8db540469c79a9606fb7085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Thu, 2 Sep 2021 07:44:30 +0000 Subject: [PATCH] [FIX] survey: avoid crash for misconfigured questions Currently, if the user configures his survey with questions of type 'simple_choice', 'multiple_choice' and 'matrix', but doesn't configure any selectable choices, the survey result page can crash. This is not really a "standard" use case but this commit adds a few checks to avoid a complete traceback and instead give empty data results. Task-2622869 closes odoo/odoo#75586 closes odoo/odoo#76606 X-original-commit: 8051be7c96417cf2feb9d542bb3d230022c8cc54 Signed-off-by: Thibault Delavallee (tde) Signed-off-by: awa-odoo --- addons/survey/static/src/js/survey_result.js | 38 ++++++++++--------- .../views/survey_templates_statistics.xml | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/addons/survey/static/src/js/survey_result.js b/addons/survey/static/src/js/survey_result.js index 74f1f24657f..de579632a6d 100644 --- a/addons/survey/static/src/js/survey_result.js +++ b/addons/survey/static/src/js/survey_result.js @@ -94,25 +94,27 @@ publicWidget.registry.SurveyResultChart = publicWidget.Widget.extend({ return this._super.apply(this, arguments).then(function () { self.graphData = self.$el.data("graphData"); - switch (self.$el.data("graphType")) { - case 'multi_bar': - self.chartConfig = self._getMultibarChartConfig(); - break; - case 'bar': - self.chartConfig = self._getBarChartConfig(); - break; - case 'pie': - self.chartConfig = self._getPieChartConfig(); - break; - case 'doughnut': - self.chartConfig = self._getDoughnutChartConfig(); - break; - case 'by_section': - self.chartConfig = self._getSectionResultsChartConfig(); - break; - } + if (self.graphData && self.graphData.length !== 0) { + switch (self.$el.data("graphType")) { + case 'multi_bar': + self.chartConfig = self._getMultibarChartConfig(); + break; + case 'bar': + self.chartConfig = self._getBarChartConfig(); + break; + case 'pie': + self.chartConfig = self._getPieChartConfig(); + break; + case 'doughnut': + self.chartConfig = self._getDoughnutChartConfig(); + break; + case 'by_section': + self.chartConfig = self._getSectionResultsChartConfig(); + break; + } - self._loadChart(); + self._loadChart(); + } }); }, diff --git a/addons/survey/views/survey_templates_statistics.xml b/addons/survey/views/survey_templates_statistics.xml index 20de2dd74c7..d89659e766b 100644 --- a/addons/survey/views/survey_templates_statistics.xml +++ b/addons/survey/views/survey_templates_statistics.xml @@ -352,7 +352,7 @@
- +