changeset e631fd8ce957 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset&node=e631fd8ce957
description:
        Set sequence order following the new position order

        issue10299
        review334181002
diffstat:

 tryton/gui/window/view_form/model/group.py                |  22 +++++++++++---
 tryton/gui/window/view_form/view/form_gtk/one2many.py     |   9 ++++--
 tryton/gui/window/view_form/view/list.py                  |   4 ++-
 tryton/gui/window/view_form/view/list_gtk/editabletree.py |   3 +-
 4 files changed, 28 insertions(+), 10 deletions(-)

diffs (108 lines):

diff -r caf5ace2ac2b -r e631fd8ce957 tryton/gui/window/view_form/model/group.py
--- a/tryton/gui/window/view_form/model/group.py        Thu Apr 22 07:56:09 
2021 +0200
+++ b/tryton/gui/window/view_form/model/group.py        Thu Apr 22 23:45:00 
2021 +0200
@@ -1,5 +1,7 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+import operator
+
 from .record import Record
 from .field import Field, M2OField, ReferenceField
 from tryton import rpc
@@ -346,9 +348,13 @@
                     field.set_client(record, value)
         return record
 
-    def set_sequence(self, field='sequence'):
+    def set_sequence(self, field='sequence', position=-1):
         changed = False
         prev = None
+        if position == 0:
+            cmp = operator.gt
+        else:
+            cmp = operator.lt
         for record in self:
             # Assume not loaded records are correctly ordered
             # as far as we do not change any previous records.
@@ -362,11 +368,17 @@
                 if value is None:
                     if index:
                         update = True
-                    elif prev and record.id >= 0:
-                        update = record.id < prev.id
+                    elif prev:
+                        if record.id >= 0:
+                            update = cmp(record.id, prev.id)
+                        elif position == 0:
+                            update = True
                 elif value == index:
-                    if prev and record.id >= 0:
-                        update = record.id < prev.id
+                    if prev:
+                        if record.id >= 0:
+                            update = cmp(record.id, prev.id)
+                        elif position == 0:
+                            update = True
                 elif value <= (index or 0):
                     update = True
                 if update:
diff -r caf5ace2ac2b -r e631fd8ce957 
tryton/gui/window/view_form/view/form_gtk/one2many.py
--- a/tryton/gui/window/view_form/view/form_gtk/one2many.py     Thu Apr 22 
07:56:09 2021 +0200
+++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py     Thu Apr 22 
23:45:00 2021 +0200
@@ -348,7 +348,8 @@
 
         def update_sequence():
             if sequence:
-                self.screen.group.set_sequence(field=sequence)
+                self.screen.group.set_sequence(
+                    field=sequence, position=self.screen.new_position)
 
         if self.screen.current_view.editable:
             self.screen.new()
@@ -408,7 +409,8 @@
 
             sequence = self._sequence()
             if sequence:
-                self.screen.group.set_sequence(field=sequence)
+                self.screen.group.set_sequence(
+                    field=sequence, position=self.screen.new_position)
 
         search_set()
 
@@ -471,7 +473,8 @@
                 self.screen.load(ids, modified=True)
                 self.screen.display(res_id=ids[0])
                 if sequence:
-                    self.screen.group.set_sequence(field=sequence)
+                    self.screen.group.set_sequence(
+                        field=sequence, position=self.screen.new_position)
             self.screen.set_cursor()
             self.wid_text.set_text('')
 
diff -r caf5ace2ac2b -r e631fd8ce957 tryton/gui/window/view_form/view/list.py
--- a/tryton/gui/window/view_form/view/list.py  Thu Apr 22 07:56:09 2021 +0200
+++ b/tryton/gui/window/view_form/view/list.py  Thu Apr 22 23:45:00 2021 +0200
@@ -831,7 +831,9 @@
         selection.unselect_all()
         selection.select_path(record.get_index_path(model.group))
         if self.attributes.get('sequence'):
-            record.group.set_sequence(field=self.attributes['sequence'])
+            record.group.set_sequence(
+                field=self.attributes['sequence'],
+                position=self.screen.new_position)
         return True
 
     def drag_drop(self, treeview, context, x, y, time):
diff -r caf5ace2ac2b -r e631fd8ce957 
tryton/gui/window/view_form/view/list_gtk/editabletree.py
--- a/tryton/gui/window/view_form/view/list_gtk/editabletree.py Thu Apr 22 
07:56:09 2021 +0200
+++ b/tryton/gui/window/view_form/view/list_gtk/editabletree.py Thu Apr 22 
23:45:00 2021 +0200
@@ -125,7 +125,8 @@
         res = method(new_record)
         sequence = self.view.attributes.get('sequence')
         if sequence:
-            model.group.set_sequence(field=sequence)
+            model.group.set_sequence(
+                field=sequence, position=self.view.screen.new_position)
         return res
 
     def set_cursor(

Reply via email to