summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-02-15 10:09:44 +0100
committerAaron Bohy <aab@odoo.com>2018-02-16 14:28:50 +0100
commitcf03101447cf572417274f06f232056d6b944237 (patch)
treec52db40526ce7ed5caa0baa9d480444c12462dcf /addons/web/static/src/js/views/basic/basic_model.js
parent0017902733bffc3bce1cdaeb8ba512a20a0a8c2c (diff)
[FIX] web: BasicModel: fetch nested x2manys after onchange
When onchange RPCs return a command 4 (LINK TO), the res_id of the record to link is given, and the BasicModel has to read the fields in the view for that record. When one of those fields is an x2many (for instance, displayed with widget many2many_tags), the subrecords in the relation must be read as well (at least their display_name). Before this rev., this last part wasn't done by the BasicModel, and as a consequence, the many2many_tags widget was always empty, even though there were records in the relation. Same thing applied to reference fields, but this is way more uncommon. This rev. ensures that x2manys and reference fields are correctly fetched in this scenario.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 68fcd05fab1..ff4ed6d9147 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1470,7 +1470,12 @@ var BasicModel = AbstractModel.extend({
list._changes = [{operation: 'REMOVE_ALL'}];
}
});
- defs.push(self._readUngroupedList(list));
+ var def = self._readUngroupedList(list).then(function () {
+ var x2ManysDef = self._fetchX2ManysBatched(list);
+ var referencesDef = self._fetchReferencesBatched(list);
+ return $.when(x2ManysDef, referencesDef);
+ });
+ defs.push(def);
} else {
var newValue = self._parseServerValue(field, val);
if (newValue !== oldValue) {
@@ -1975,7 +1980,9 @@ var BasicModel = AbstractModel.extend({
_.each(list.data, function (dataPoint) {
var record = self.localData[dataPoint];
var value = record.data[fieldName];
- if (value) {
+ // if the reference field has already been fetched, the value is a
+ // datapoint ID, and in this case there's nothing to do
+ if (value && !self.localData[value]) {
var model = value.split(',')[0];
var resID = value.split(',')[1];
if (!(model in toFetch)) {