diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index fae5ecb4e2..5f0074d33e 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -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 @@ class Group(SignalEvent, list): 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 @@ class Group(SignalEvent, list): 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 --git a/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/gui/window/view_form/view/form_gtk/one2many.py index 7fe49531ec..5d80af36ea 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -348,7 +348,8 @@ class One2Many(Widget): 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 @@ class One2Many(Widget): 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 @@ class One2Many(Widget): 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 --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 33422bda2c..91b2482d26 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -831,7 +831,9 @@ class ViewTree(View): 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 --git a/tryton/gui/window/view_form/view/list_gtk/editabletree.py b/tryton/gui/window/view_form/view/list_gtk/editabletree.py index 8ec3398513..6dacbbc694 100644 --- a/tryton/gui/window/view_form/view/list_gtk/editabletree.py +++ b/tryton/gui/window/view_form/view/list_gtk/editabletree.py @@ -125,7 +125,8 @@ class EditableTreeView(TreeView): 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(