changeset 2efc45374223 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=2efc45374223
description:
Ensure field is loaded before applying changes
For fields like xxx2Many the changed values are operation to apply on
the
existing value. So we must be sure to have loaded the value.
issue9730
review314491002
diffstat:
src/model.js | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
diffs (70 lines):
diff -r e3d683dfad46 -r 2efc45374223 src/model.js
--- a/src/model.js Wed Oct 21 23:15:18 2020 +0200
+++ b/src/model.js Wed Oct 21 23:28:09 2020 +0200
@@ -622,11 +622,14 @@
is_loaded: function(name) {
return ((this.id < 0) || (name in this._loaded));
},
- load: function(name) {
+ load: function(name, async) {
var fname;
var prm;
+ if (async === undefined) {
+ async = true;
+ }
if (this.is_loaded(name)) {
- return jQuery.when();
+ return async? jQuery.when() : this.model.fields[name];
}
if (this.group.prm.state() == 'pending') {
return this.group.prm.then(function() {
@@ -751,9 +754,9 @@
context[this.model.name + '.' + fname] = 'size';
}
}
- prm = this.model.execute('read', [Object.keys(id2record).map(
+ var result = this.model.execute('read',
[Object.keys(id2record).map(
function (e) { return parseInt(e, 10); }),
- fnames_to_fetch], context);
+ fnames_to_fetch], context, async);
var succeed = function(values, exception) {
if (exception === undefined) exception = false;
var id2value = {};
@@ -794,8 +797,17 @@
}
return succeed(failed_values, true);
};
- this.group.prm = prm.then(succeed, failed);
- return this.group.prm;
+ if (async) {
+ this.group.prm = result.then(succeed, failed);
+ return this.group.prm;
+ } else {
+ if (result) {
+ succeed(result);
+ } else {
+ failed();
+ }
+ return this.model.fields[name];
+ }
},
set: function(values, validate) {
if (validate === undefined) {
@@ -1130,7 +1142,7 @@
} catch (e) {
return;
}
- this.model.fields[fieldname].set_on_change(this, result);
+ this.load(fieldname, false).set_on_change(this, result);
}
},
set_on_change: function(values) {
@@ -1147,7 +1159,7 @@
var related = fieldname + '.';
this._values[related] = values[related] || {};
}
- this.model.fields[fieldname].set_on_change(this, value);
+ this.load(fieldname, false).set_on_change(this, value);
}
},
autocomplete_with: function(fieldname) {