details:   https://code.tryton.org/tryton/commit/310920c05b93
branch:    8.0
user:      Cédric Krier <[email protected]>
date:      Thu Sep 17 16:18:47 2026 +0200
description:
        Store any selection in selection mixin to compute textual value

        Since 917de1b3e124 the current selection is no more stored but it is 
needed to
        render textual value of a column synchronously.

        Closes #15104
        (grafted from 2b97e6681d99b4172aceb3a45557e92e2420795b)
diffstat:

 sao/src/common.js    |  12 ++++++++++--
 sao/src/view/tree.js |  43 +++++++++++++++----------------------------
 2 files changed, 25 insertions(+), 30 deletions(-)

diffs (137 lines):

diff -r a8bdc2816c3b -r 310920c05b93 sao/src/common.js
--- a/sao/src/common.js Wed Sep 16 23:56:56 2026 +0200
+++ b/sao/src/common.js Thu Sep 17 16:18:47 2026 +0200
@@ -767,6 +767,7 @@
     Sao.common.selection_mixin = {};
     Sao.common.selection_mixin.init = function() {
         this.inactive_selection = [];
+        this.any_selection = {}
         this._values2selection = {};
         this._domain_cache = {};
         if (this.nullable_widget === undefined) {
@@ -791,6 +792,7 @@
                 });
             }
             let help = this.attributes.help_selection || {};
+            Object.assign(this.any_selection, Object.fromEntries(selection));
             if (callback) callback(selection, help);
         };
         if (!(selection instanceof Array) &&
@@ -839,6 +841,9 @@
                             selection = Sao.common.selection_mixin
                                 .filter_selection.call(
                                     this, domain, record, field, selection);
+                            Object.assign(
+                                this.any_selection,
+                                Object.fromEntries(selection));
                             if (callback) {
                                 callback(selection, help);
                             }
@@ -879,6 +884,8 @@
                         }
                     }
                     this._domain_cache[jdomain] = [selection, help];
+                    Object.assign(
+                        this.any_selection, Object.fromEntries(selection));
 
                     let cur_domain = field.get_domain(record);
                     let cur_context = field.get_context(record);
@@ -959,8 +966,9 @@
             'params': [[value], ['rec_name'], {}]
         }, Sao.Session.current_session);
         return prm.then(result => {
-            this.inactive_selection.push([result[0].id, result[0].rec_name]);
-            return [result[0].id, result[0].rec_name];
+            let selection = [result[0].id, result[0].rec_name];
+            this.inactive_selection.push(selection);
+            return selection;
         });
     };
 
diff -r a8bdc2816c3b -r 310920c05b93 sao/src/view/tree.js
--- a/sao/src/view/tree.js      Wed Sep 16 23:56:56 2026 +0200
+++ b/sao/src/view/tree.js      Thu Sep 17 16:18:47 2026 +0200
@@ -2876,37 +2876,29 @@
                 return record._values[related];
             } else {
                 var value = this.field.get(record);
-                for (const option of this.selection) {
-                    if (option[0] === value) {
-                        return option[1];
-                    }
+                if (Object.hasOwn(this.any_selection, value)) {
+                    return this.any_selection[value];
+                } else {
+                    return value;
                 }
-                return value;
             }
         },
         update_text: function(cell, record) {
             if (!this.tree.editable &&
                     (this.field.name + ':string' in record._values)) {
-                var text_value = this.get_textual_value(record);
+                let text_value = record._values[this.field.name + ':string'];
                 cell.text(text_value).attr('title', text_value);
             } else {
                 this.update_selection(record, (selection, help) => {
-                    var value = this.field.get(record);
-                    var prm, text, found = false;
-                    for (const option of selection) {
-                        if (option[0] === value) {
-                            found = true;
-                            text = option[1];
-                            break;
-                        }
-                    }
-                    if (!found) {
+                    let value = this.field.get(record),
+                        prm;
+                    if (Object.hasOwn(this.any_selection, value)) {
+                        prm = jQuery.when(this.any_selection[value]);
+                    } else {
                         prm = Sao.common.selection_mixin.get_inactive_selection
                             .call(this, value).then(function(inactive) {
                                 return inactive[1];
                             });
-                    } else {
-                        prm = jQuery.when(text);
                     }
                     prm.done(text_value => {
                         cell.text(text_value).attr('title', text_value);
@@ -2937,10 +2929,8 @@
                 return record._values[related];
             } else {
                 var values = this.field.get_eval(record).map(value => {
-                    for (const option of this.selection) {
-                        if (option[0] === value) {
-                            return option[1];
-                        }
+                    if (Object.hasOwn(this.any_selection, value)) {
+                        return this.any_selection[value];
                     }
                     return '';
                 });
@@ -2950,7 +2940,7 @@
         update_text: function(cell, record) {
             if (!this.tree.editable &&
                     (this.field_name + ':string' in record._values)) {
-                var text_value = this.get_textual_value(record);
+                let text_value = record._values[this.field_name + ':string'];
                 cell.text(text_value).attr('title', text_value);
             } else {
                 this.update_selection(record, () => {
@@ -2996,11 +2986,8 @@
                 name = value[1];
             }
             if (model) {
-                for (const option of this.selection) {
-                    if (option[0] === model) {
-                        model = option[1];
-                        break;
-                    }
+                if (Object.hasOwn(this.any_selection, model)) {
+                    model = this.any_selection[model];
                 }
                 text = model + ',' + name;
             } else {

Reply via email to