summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorfwi-odoo <fwi@odoo.com>2017-04-14 13:02:21 +0200
committerfwi-odoo <fwi@odoo.com>2017-04-20 16:41:59 +0200
commit86af036ea1175f4a9a5fbca806ab49665fdbc4b0 (patch)
treef9d69f2c5c5c766a9a457df59738fea4194a6250 /addons/web/static/src/js/views/basic/basic_model.js
parent6da35f7140246d19755da913b4c84fdc16759474 (diff)
[FIX] web: fix various bugs when fetching x2manys in form views
- When an one2many is displayed in a list view, the field data are not fully loaded since only the number of record is displayed. Then when the related form view is opened the one2many fields displayed need to be loaded. - Optimized the fetch of x2manys without doing an useless rpc if we don't need all the fields but only the relation records ids and adapt the tests for this optimisation. - Fix wrong inheritance for kanbanmany2many_tags
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.js76
1 files changed, 46 insertions, 30 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 b3777a05efb..4b39025b35d 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1619,40 +1619,50 @@ var BasicModel = AbstractModel.extend({
if (!ids.length || fieldInfo.__no_fetch) {
return $.when();
}
-
+ var def;
+ var fieldNames = _.keys(fieldInfo.relatedFields);
// step 2: fetch data from server
- return this._rpc({
+ // if we want specific fields
+ // if not we return an array of objects with the id
+ // to avoid fetching all the relation fields and an useless rpc
+ if (fieldNames.length) {
+ def = this._rpc({
model: field.relation,
method: 'read',
- args: [ids, _.keys(fieldInfo.relatedFields)],
+ args: [ids, fieldNames],
context: {}, // FIXME
- })
- .then(function (results) {
- // step 3: assign values to correct datapoints
- var dataPoints = _.map(results, function (result) {
- return self._makeDataPoint({
- modelName: field.relation,
- data: result,
- fields: fields,
- fieldsInfo: fieldsInfo,
- viewType: viewType,
- });
+ });
+ } else {
+ def = $.when(_.map(ids, function (id) {
+ return {id:id};
+ }));
+ }
+ return def.then(function (results) {
+ // step 3: assign values to correct datapoints
+ var dataPoints = _.map(results, function (result) {
+ return self._makeDataPoint({
+ modelName: field.relation,
+ data: result,
+ fields: fields,
+ fieldsInfo: fieldsInfo,
+ viewType: viewType,
});
+ });
- _.each(list.data, function (dataPoint) {
- var record = self.localData[dataPoint];
- var m2mList = self.localData[record.data[fieldName]];
+ _.each(list.data, function (dataPoint) {
+ var record = self.localData[dataPoint];
+ var m2mList = self.localData[record.data[fieldName]];
- m2mList.data = [];
- _.each(m2mList.res_ids, function (res_id) {
- var dataPoint = _.find(dataPoints, function (d) {
- return d.res_id === res_id;
- });
- m2mList.data.push(dataPoint.id);
- m2mList.count++;
+ m2mList.data = [];
+ _.each(m2mList.res_ids, function (res_id) {
+ var dataPoint = _.find(dataPoints, function (d) {
+ return d.res_id === res_id;
});
+ m2mList.data.push(dataPoint.id);
+ m2mList.count++;
});
});
+ });
},
/**
* batch request for x2ms for datapoint of type list
@@ -2444,12 +2454,18 @@ var BasicModel = AbstractModel.extend({
}
}
if (missingIds.length) {
- def = this._rpc({
- model: list.model,
- method: 'read',
- args: [missingIds, fieldNames],
- context: {} // FIXME
- });
+ if (fieldNames.length) {
+ def = this._rpc({
+ model: list.model,
+ method: 'read',
+ args: [missingIds, fieldNames],
+ context: {} // FIXME
+ });
+ } else {
+ def = $.when(_.map(missingIds, function (id) {
+ return {id:id};
+ }));
+ }
} else {
def = $.when();
}