changeset 250b0e8db8ef in sao:5.0
details: https://hg.tryton.org/sao?cmd=changeset;node=250b0e8db8ef
description:
        Skip destroyed records when fetching data from the server

        issue9669
        review294631002
        (grafted from e20c9e4289c1ef91c8bcd37af4a9bcbfe835e609)
diffstat:

 src/model.js |  18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diffs (56 lines):

diff -r 8950a9d74310 -r 250b0e8db8ef src/model.js
--- a/src/model.js      Thu Oct 29 00:01:48 2020 +0100
+++ b/src/model.js      Fri Oct 30 19:01:11 2020 +0100
@@ -267,6 +267,7 @@
             context._timestamp = {};
             records.forEach(function(record) {
                 jQuery.extend(context._timestamp, record.get_timestamp());
+                record.destroy();
             });
             var record_ids = records.map(function(record) {
                 return record.id;
@@ -509,6 +510,7 @@
             this.state_attrs = {};
             this.autocompletion = {};
             this.exception = false;
+            this.destroyed = false;
         },
         has_changed: function() {
             return !jQuery.isEmptyObject(this._changed);
@@ -572,7 +574,7 @@
         load: function(name) {
             var fname;
             var prm;
-            if ((this.id < 0) || (name in this._loaded)) {
+            if (this.destroyed || (this.id < 0) || (name in this._loaded)) {
                 return jQuery.when();
             }
             if (this.group.prm.state() == 'pending') {
@@ -641,7 +643,9 @@
                         10);
 
                 var filter_group = function(record) {
-                    return !(name in record._loaded) && (record.id >= 0);
+                    return (!record.destroyed &&
+                        (record.id >= 0) &&
+                        !(name in record._loaded));
                 };
                 var filter_parent_group = function(record) {
                     return (filter_group(record) &&
@@ -1354,6 +1358,16 @@
                 this.button_clicks[name] = clicks;
                 return clicks;
             }.bind(this));
+        },
+        destroy: function() {
+            var vals = Object.values(this._values);
+            for (var i=0; i < vals.length; i++) {
+                var val = vals[i];
+                if (val.hasOwnProperty('destroy')) {
+                    val.destroy();
+                }
+            }
+            this.destroyed = true;
         }
     });
 

Reply via email to