diff --git a/sao/src/screen.js b/sao/src/screen.js index 7e5a715f52c..f1a5922afac 100644 --- a/sao/src/screen.js +++ b/sao/src/screen.js @@ -1218,11 +1218,7 @@ if (this.group.parent) { this.order = null; } - if (group && (group.length > 0)) { - this.current_record = group[0]; - } else { - this.current_record = null; - } + this.current_record = null; this.group.add_fields(fields); for (name in fields_views) { var views = fields_views[name]; @@ -1326,11 +1322,7 @@ load: function(ids, set_cursor=true, modified=false, position=-1) { this.group.load(ids, null, modified, position); this.current_view.reset(); - if ((ids.length > 0) && (this.current_view.view_type == 'tree')) { - this.current_record = this.group.get(ids[0]); - } else { - this.current_record = null; - } + this.current_record = null; return this.display().then(() => { if (set_cursor) { this.set_cursor(); @@ -1384,7 +1376,7 @@ if (this.current_record && ~this.current_record.group.indexOf(this.current_record)) { } else if (this.group && this.group.length && - (['form', 'tree'].includes(this.current_view.view_type))) { + (this.current_view.view_type == 'form')) { this.current_record = this.group[0]; } else { this.current_record = null; diff --git a/sao/src/view/tree.js b/sao/src/view/tree.js index 8197307d393..32e87c1f70a 100644 --- a/sao/src/view/tree.js +++ b/sao/src/view/tree.js @@ -937,8 +937,12 @@ moreObserver.observe(more_button[0]); } } - }).done( - Sao.common.debounce(this.update_sum.bind(this), 250)); + }).done(() => { + if (!this.record && this.rows.length) { + this.rows[0].select_row({}); + } + Sao.common.debounce(this.update_sum.bind(this), 250)(); + }); }, construct: function(extend) { if (!extend) { diff --git a/tryton/tryton/gui/window/view_form/screen/screen.py b/tryton/tryton/gui/window/view_form/screen/screen.py index 7c0cf307e45..19288d78c34 100644 --- a/tryton/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/tryton/gui/window/view_form/screen/screen.py @@ -429,10 +429,7 @@ def __set_group(self, group): self.filter_widget = None self.order = None self.__group.add_fields(fields) - if group: - self.current_record = group[0] - else: - self.current_record = None + 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 @@ -1010,10 +1007,7 @@ 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() - if ids and self.current_view.view_type == 'tree': - self.current_record = self.group.get(ids[0]) - else: - self.current_record = None + self.current_record = None self.display(set_cursor=set_cursor) def display(self, res_id=None, set_cursor=False, force=False): @@ -1023,8 +1017,7 @@ def display(self, res_id=None, set_cursor=False, force=False): if (self.current_record and self.current_record in self.current_record.group): pass - elif (self.group - and self.current_view.view_type in {'form', 'tree'}): + elif self.group and self.current_view.view_type == 'form': self.current_record = self.group[0] else: self.current_record = None diff --git a/tryton/tryton/gui/window/view_form/view/list.py b/tryton/tryton/gui/window/view_form/view/list.py index 793cb535950..ffd63d9fd4c 100644 --- a/tryton/tryton/gui/window/view_form/view/list.py +++ b/tryton/tryton/gui/window/view_form/view/list.py @@ -1203,6 +1203,11 @@ def display(self, force=False): self.set_state() self.update_arrow() self.update_sum() + if not self.record and self.group: + record = self.group[0] + selection = self.treeview.get_selection() + selection.unselect_all() + selection.select_path(record.get_index_path(self.group)) # Set column visibility depending on attributes and domain domain = []