changeset 74557f917ae5 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset;node=74557f917ae5
description:
        Ensure sort key always return an integer

        When sorting tree model, it is possible that some ids are not in the 
ordered
        list (because they do not fit anymore in the domain). So we return the 
number
        of records so they are moved at the end of the list.

        issue8042
        review53531002
diffstat:

 tryton/gui/window/view_form/view/list.py |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diffs (13 lines):

diff -r 57b75ada1af4 -r 74557f917ae5 tryton/gui/window/view_form/view/list.py
--- a/tryton/gui/window/view_form/view/list.py  Sun Feb 03 20:25:03 2019 +0100
+++ b/tryton/gui/window/view_form/view/list.py  Sun Feb 03 20:29:09 2019 +0100
@@ -143,7 +143,8 @@
     def sort(self, ids):
         old_idx = {record.id: i for i, record in enumerate(self.group)}
         new_idx = {id_: i for i, id_ in enumerate(ids)}
-        self.group.sort(key=lambda r: new_idx.get(r.id))
+        size = len(self.group)
+        self.group.sort(key=lambda r: new_idx.get(r.id, size))
         new_order = []
         prev = None
         for record in self.group:

Reply via email to