details:   https://code.tryton.org/tryton/commit/05e1fff8ebc5
branch:    default
user:      Nicolas Évrard <[email protected]>
date:      Wed Apr 01 18:24:35 2026 +0200
description:
        Honor the sort parameter of Selection fields in the filter box

        Closes #14731
diffstat:

 sao/src/screen.js                                           |  8 +++++++-
 tryton/tryton/gui/window/view_form/view/screen_container.py |  3 +++
 2 files changed, 10 insertions(+), 1 deletions(-)

diffs (39 lines):

diff -r 6a38e1f9f069 -r 05e1fff8ebc5 sao/src/screen.js
--- a/sao/src/screen.js Tue Mar 31 15:35:28 2026 +0200
+++ b/sao/src/screen.js Wed Apr 01 18:24:35 2026 +0200
@@ -501,8 +501,14 @@
                             break;
                         case 'selection':
                         case 'multiselection':
+                            var selection = jQuery.extend([], field.selection);
+                            if (field.sort === undefined || field.sort) {
+                                selection.sort(function(a, b) {
+                                    return a[1].localeCompare(b[1]);
+                                });
+                            }
                             entry = new Sao.ScreenContainer.Selection(
-                                    field.selection, prefix + field.name);
+                                    selection, prefix + field.name);
                             input = entry.el;
                             input.prop('size', field.selection.length);
                             break;
diff -r 6a38e1f9f069 -r 05e1fff8ebc5 
tryton/tryton/gui/window/view_form/view/screen_container.py
--- a/tryton/tryton/gui/window/view_form/view/screen_container.py       Tue Mar 
31 15:35:28 2026 +0200
+++ b/tryton/tryton/gui/window/view_form/view/screen_container.py       Wed Apr 
01 18:24:35 2026 +0200
@@ -2,6 +2,7 @@
 # this repository contains the full copyright notices and license terms.
 import datetime
 import gettext
+import operator
 
 from gi.repository import Gdk, GLib, GObject, Gtk
 
@@ -627,6 +628,8 @@
                         entry.append_text(selection)
                 elif field['type'] in ['selection', 'multiselection']:
                     selections = tuple(x[1] for x in field['selection'])
+                    if field.get('sort', True):
+                        selections.sort(key=operator.itemgetter(1))
                     entry = Selection(selections)
                     entry.set_vexpand(True)
                 elif field['type'] in ('date', 'datetime', 'time'):

Reply via email to