diff --git a/sao/src/screen.js b/sao/src/screen.js index f1a5922afac..7e5a715f52c 100644 --- a/sao/src/screen.js +++ b/sao/src/screen.js @@ -1218,7 +1218,11 @@ if (this.group.parent) { this.order = null; } - this.current_record = null; + if (group && (group.length > 0)) { + this.current_record = group[0]; + } else { + this.current_record = null; + } this.group.add_fields(fields); for (name in fields_views) { var views = fields_views[name]; @@ -1322,7 +1326,11 @@ load: function(ids, set_cursor=true, modified=false, position=-1) { this.group.load(ids, null, modified, position); this.current_view.reset(); - this.current_record = null; + if ((ids.length > 0) && (this.current_view.view_type == 'tree')) { + this.current_record = this.group.get(ids[0]); + } else { + this.current_record = null; + } return this.display().then(() => { if (set_cursor) { this.set_cursor(); @@ -1376,7 +1384,7 @@ if (this.current_record && ~this.current_record.group.indexOf(this.current_record)) { } else if (this.group && this.group.length && - (this.current_view.view_type == 'form')) { + (['form', 'tree'].includes(this.current_view.view_type))) { this.current_record = this.group[0]; } else { this.current_record = null; diff --git a/tryton/tryton/gui/window/view_form/screen/screen.py b/tryton/tryton/gui/window/view_form/screen/screen.py index a2554253c62..7c0cf307e45 100644 --- a/tryton/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/tryton/gui/window/view_form/screen/screen.py @@ -429,7 +429,10 @@ def __set_group(self, group): self.filter_widget = None self.order = None self.__group.add_fields(fields) - self.current_record = None + if group: + self.current_record = group[0] + else: + self.current_record = None for name, views in fields_views.items(): self.__group.fields[name].views.update(views) self.__group.exclude_field = self.exclude_field @@ -1007,18 +1010,21 @@ def get_tree_domain(self, parent): def load(self, ids, set_cursor=True, modified=False, position=-1): self.group.load(ids, modified=modified, position=position) self.current_view.reset() - self.current_record = None + if ids and self.current_view.view_type == 'tree': + self.current_record = self.group.get(ids[0]) + else: + self.current_record = None self.display(set_cursor=set_cursor) def display(self, res_id=None, set_cursor=False, force=False): - start = time.time() if res_id: self.current_record = self.group.get(res_id) else: if (self.current_record and self.current_record in self.current_record.group): pass - elif self.group and self.current_view.view_type == 'form': + elif (self.group + and self.current_view.view_type in {'form', 'tree'}): self.current_record = self.group[0] else: self.current_record = None