details:   https://code.tryton.org/tryton/commit/dc3a3e200063
branch:    default
user:      Cédric Krier <[email protected]>
date:      Fri Aug 14 12:55:53 2026 +0200
description:
        Add record changed callback

        Only when the current record has changed that those objects needs to be
        refreshed/cleared:

            - the info bar
            - the resources
            - the attachment preview
            - the chat

        Closes #15012
diffstat:

 sao/src/screen.js                                   |  26 +++++++++++++-------
 sao/src/tab.js                                      |  20 ++++++++-------
 tryton/tryton/gui/window/form.py                    |  26 +++++++++++---------
 tryton/tryton/gui/window/view_form/screen/screen.py |  11 ++++++--
 4 files changed, 50 insertions(+), 33 deletions(-)

diffs (153 lines):

diff -r 80f38dd8024d -r dc3a3e200063 sao/src/screen.js
--- a/sao/src/screen.js Fri Aug 14 18:11:42 2026 +0200
+++ b/sao/src/screen.js Fri Aug 14 12:55:53 2026 +0200
@@ -1364,6 +1364,7 @@
             return this.__current_record;
         },
         set current_record(record) {
+            let changed = this.__current_record !== record;
             this.__current_record = record;
             var pos = null;
             var record_id = null;
@@ -1379,15 +1380,22 @@
             this.record_message(
                 pos || 0, this.group.length + this.offset, this.search_count,
                 record_id);
-            if (this.switch_callback) {
-                this.switch_callback();
-            }
-            if (this.has_update_resources()) {
-                if (record) {
-                    record.get_resources().always(
-                        this.update_resources.bind(this));
-                } else {
-                    this.update_resources();
+            if (changed) {
+                for (let window_ of this.windows) {
+                    if (window_.record_changed) {
+                        window_.record_changed();
+                    }
+                }
+                if (this.switch_callback) {
+                    this.switch_callback();
+                }
+                if (this.has_update_resources()) {
+                    if (record) {
+                        record.get_resources().always(
+                            this.update_resources.bind(this));
+                    } else {
+                        this.update_resources();
+                    }
                 }
             }
         },
diff -r 80f38dd8024d -r dc3a3e200063 sao/src/tab.js
--- a/sao/src/tab.js    Fri Aug 14 18:11:42 2026 +0200
+++ b/sao/src/tab.js    Fri Aug 14 12:55:53 2026 +0200
@@ -1621,8 +1621,18 @@
                 msg = name + '/' + Sao.common.humanize(size);
             }
             this.status_label.text(msg).attr('title', msg);
+            this.set_buttons_sensitive();
+        },
+        record_modified: function() {
+            this.set_buttons_sensitive();
+            this.info_bar.refresh();
+        },
+        record_saved: function() {
+            this.set_buttons_sensitive();
+            this.refresh_resources();
+        },
+        record_changed: function() {
             this.info_bar.clear();
-            this.set_buttons_sensitive();
             this.refresh_attachment_preview();
 
             if (this._chat) {
@@ -1637,14 +1647,6 @@
                 this.update_sidebar();
             }
         },
-        record_modified: function() {
-            this.set_buttons_sensitive();
-            this.info_bar.refresh();
-        },
-        record_saved: function() {
-            this.set_buttons_sensitive();
-            this.refresh_resources();
-        },
         action: function() {
             window.setTimeout(() => {
                 this.buttons.action.click();
diff -r 80f38dd8024d -r dc3a3e200063 tryton/tryton/gui/window/form.py
--- a/tryton/tryton/gui/window/form.py  Fri Aug 14 18:11:42 2026 +0200
+++ b/tryton/tryton/gui/window/form.py  Fri Aug 14 12:55:53 2026 +0200
@@ -664,19 +664,7 @@
         else:
             msg = "%s/%s" % (name, common.humanize(size))
         self.status_label.set_text(msg)
-        self.info_bar_clear()
         self.set_buttons_sensitive()
-        self.refresh_attachment_preview()
-        if self._chat:
-            self._chat.unregister()
-            self.chat.remove(self._chat.widget)
-            if self.screen.current_reference:
-                self._chat = Chat(self.screen.current_reference)
-                self.chat.add(self._chat.widget)
-                self.chat.show_all()
-                self._chat.refresh()
-            else:
-                self.buttons['chat'].set_active(False)
 
     def record_modified(self):
         def _record_modified():
@@ -691,6 +679,20 @@
         self.set_buttons_sensitive()
         self.refresh_resources()
 
+    def record_changed(self):
+        self.info_bar_clear()
+        self.refresh_attachment_preview()
+        if self._chat:
+            self._chat.unregister()
+            self.chat.remove(self._chat.widget)
+            if self.screen.current_reference:
+                self._chat = Chat(self.screen.current_reference)
+                self.chat.add(self._chat.widget)
+                self.chat.show_all()
+                self._chat.refresh()
+            else:
+                self.buttons['chat'].set_active(False)
+
     def modified_save(self):
         self.screen.save_tree_state()
         self.screen.current_view.set_value()
diff -r 80f38dd8024d -r dc3a3e200063 
tryton/tryton/gui/window/view_form/screen/screen.py
--- a/tryton/tryton/gui/window/view_form/screen/screen.py       Fri Aug 14 
18:11:42 2026 +0200
+++ b/tryton/tryton/gui/window/view_form/screen/screen.py       Fri Aug 14 
12:55:53 2026 +0200
@@ -504,6 +504,7 @@
         return self.__current_record
 
     def __set_current_record(self, record):
+        changed = self.__current_record != record
         self.__current_record = record
         if record:
             try:
@@ -516,9 +517,13 @@
         self.record_message(
             pos, len(self.group) + self.offset,
             self.search_count, record and record.id)
-        self.update_resources(record.resources if record else None)
-        # update resources after 1 second
-        GLib.timeout_add(1000, self._update_resources, record)
+        if changed:
+            for window in self.windows:
+                if hasattr(window, 'record_changed'):
+                    window.record_changed()
+            self.update_resources(record.resources if record else None)
+            # update resources after 1 second
+            GLib.timeout_add(1000, self._update_resources, record)
 
     current_record = property(__get_current_record, __set_current_record)
 

Reply via email to