From 3869b080aeff72aef857d581b7084f60d271ab4a Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 19 Mar 2018 12:14:03 +0100 Subject: [PATCH] [FIX] survey: preserve the multiple choices question answers order When configuring a survey with a Multiple choice: only one answer question, the answers shown in the result may be in the wrong order because of the use of a simple `Dict` instead of an `OrderedDict`. The behavior was increased when using Python 3.5, as it randomizes on purpose dictionnaries. opw-1818797 --- addons/survey/models/survey.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/survey/models/survey.py b/addons/survey/models/survey.py index d5d249fe128..3cc69eb4eb6 100644 --- a/addons/survey/models/survey.py +++ b/addons/survey/models/survey.py @@ -227,9 +227,8 @@ class Survey(models.Model): # Calculate and return statistics for choice if question.type in ['simple_choice', 'multiple_choice']: - answers = {} comments = [] - [answers.update({label.id: {'text': label.value, 'count': 0, 'answer_id': label.id}}) for label in question.labels_ids] + answers = OrderedDict((label.id, {'text': label.value, 'count': 0, 'answer_id': label.id}) for label in question.labels_ids) for input_line in question.user_input_line_ids: if input_line.answer_type == 'suggestion' and answers.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters): answers[input_line.value_suggested.id]['count'] += 1