summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-03-15 14:45:13 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit1e9b695ef16baf5e28915115fd34f72a2d767cf9 (patch)
tree8eea2d933445d18ba24dcaa778a11b6be8f3d48c /addons/web/static/src/js/views/basic
parentce36786038b7b9bfa3e292ce40207d1ea46f3c92 (diff)
[FIX] web: BasicModel: always reload x2many fields
Before this commit, the relational data of a record was only fetched once, and then retrieved from the cache. This was premature optimization, that can lead to bugs as those relational data displayed in the webclient might be desynchronized with the actual data in DB.
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js49
1 files changed, 18 insertions, 31 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 7d33d51257f..6c59d242cb0 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1300,7 +1300,6 @@ var BasicModel = AbstractModel.extend({
_fetchRecord: function (record, fieldNames) {
var self = this;
fieldNames = fieldNames || _.uniq(record.fieldNames.concat(['display_name']));
- var oldData = record.data;
return this._rpc(record.model, 'read')
.args([[record.res_id], fieldNames])
// .withContext({ bin_size: true }) // FIXME: when editing a subrecord in the partner form view, it tries to write the bin_size on the image field
@@ -1313,7 +1312,7 @@ var BasicModel = AbstractModel.extend({
self._parseServerData(fieldNames, record.fields, record.data);
})
.then(function () {
- return self._fetchX2Manys(record, oldData, fieldNames).then(function () {
+ return self._fetchX2Manys(record, fieldNames).then(function () {
return self._postprocess(record);
});
});
@@ -1591,44 +1590,32 @@ var BasicModel = AbstractModel.extend({
* useless rpcs.
*
* @param {Object} record local resource
- * @param {Object} oldData the data fetched previously
* @param {string[]} [fieldNames] list of fields to fetch
* @returns {Deferred}
*/
- _fetchX2Manys: function (record, oldData, fieldNames) {
+ _fetchX2Manys: function (record, fieldNames) {
var self = this;
var defs = [];
fieldNames = fieldNames || record.fieldNames;
_.each(fieldNames, function (fieldName) {
var field = record.fields[fieldName];
if (field.type === 'one2many' || field.type === 'many2many') {
- var list;
-
- // a previously loaded list exists
- if (oldData[fieldName]) {
- list = self.localData[oldData[fieldName]];
- list.res_ids = record.data[fieldName];
- list.count = list.res_ids.length;
- list.offset = list.offset < list.count ? list.offset : 0;
- } else {
- // need to create a list from scratch
- var attrs = record.fieldAttrs[fieldName];
- var rawContext = attrs && attrs.context;
- var ids = record.data[fieldName] || [];
- list = self._makeDataPoint({
- count: ids.length,
- fieldAttrs: field.fieldAttrs,
- fields: field.relatedFields,
- limit: field.limit,
- modelName: field.relation,
- res_ids: ids,
- static: true,
- type: 'list',
- parentID: record.id,
- rawContext: rawContext,
- relationField: field.relation_field,
- });
- }
+ var attrs = record.fieldAttrs[fieldName];
+ var rawContext = attrs && attrs.context;
+ var ids = record.data[fieldName] || [];
+ var list = self._makeDataPoint({
+ count: ids.length,
+ fieldAttrs: field.fieldAttrs,
+ fields: field.relatedFields,
+ limit: field.limit,
+ modelName: field.relation,
+ res_ids: ids,
+ static: true,
+ type: 'list',
+ parentID: record.id,
+ rawContext: rawContext,
+ relationField: field.relation_field,
+ });
record.data[fieldName] = list.id;
if (!field.__no_fetch) {
var def = self._readUngroupedList(list).then(function () {