summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-07-05 17:21:01 +0200
committerChristophe Simonis <chs@odoo.com>2018-07-05 17:21:01 +0200
commit45329c0cf2c5158f7c7ccdae888adbaf2e15e7ca (patch)
tree350d68b091b113ea31f551b05d2d82991259b6a9 /addons/web/static/src/js/views/basic
parent43e4d63d069e16e64a768ef4742a5d4fca177f0c (diff)
parent84210074e55d906ea3c36e3a79741f83c5a55215 (diff)
[MERGE] forward port branch 11.0 up to 84210074e55
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js139
1 files changed, 75 insertions, 64 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 919bb179c2c..9b72918e567 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -814,7 +814,8 @@ var BasicModel = AbstractModel.extend({
return this.mutex.exec(this._applyChange.bind(this, record_id, changes, options));
},
/**
- * Reload all data for a given resource
+ * Reload all data for a given resource. At any time there is at most one
+ * reload operation active.
*
* @param {string} id local id for a resource
* @param {Object} [options]
@@ -823,64 +824,7 @@ var BasicModel = AbstractModel.extend({
* @returns {Deferred<string>} resolves to the id of the resource
*/
reload: function (id, options) {
- options = options || {};
- var element = this.localData[id];
-
- if (element.type === 'record') {
- if (!options.currentId && (('currentId' in options) || this.isNew(id))) {
- var params = {
- context: element.context,
- fieldsInfo: element.fieldsInfo,
- fields: element.fields,
- viewType: element.viewType,
- };
- return this._makeDefaultRecord(element.model, params);
- }
- if (!options.keepChanges) {
- this.discardChanges(id, {rollback: false});
- }
- } else if (element._changes) {
- delete element.tempLimitIncrement;
- _.each(element._changes, function (change) {
- delete change.isNew;
- });
- }
-
- if (options.context !== undefined) {
- element.context = options.context;
- }
- if (options.domain !== undefined) {
- element.domain = options.domain;
- }
- if (options.groupBy !== undefined) {
- element.groupedBy = options.groupBy;
- }
- if (options.limit !== undefined) {
- element.limit = options.limit;
- }
- if (options.offset !== undefined) {
- this._setOffset(element.id, options.offset);
- }
- if (options.loadMoreOffset !== undefined) {
- element.loadMoreOffset = options.loadMoreOffset;
- } else {
- // reset if not specified
- element.loadMoreOffset = 0;
- }
- if (options.currentId !== undefined) {
- element.res_id = options.currentId;
- }
- if (options.ids !== undefined) {
- element.res_ids = options.ids;
- element.count = element.res_ids.length;
- }
- if (element.type === 'record') {
- element.offset = _.indexOf(element.res_ids, element.res_id);
- }
- var loadOptions = _.pick(options, 'fieldNames', 'viewType');
- return this._load(element, loadOptions).then(function (result) {
- return result.id;
- });
+ return this.mutex.exec(this._reload.bind(this, id, options));
},
/**
* In some case, we may need to remove an element from a list, without going
@@ -2917,13 +2861,10 @@ var BasicModel = AbstractModel.extend({
continue;
}
changes = this._generateChanges(relRecord, options);
- if (changes.id) {
+ if (!this.isNew(relRecord.id)) {
// the subrecord already exists in db
+ commands[fieldName].push(x2ManyCommands.link_to(relRecord.res_id));
delete changes.id;
- if (this.isNew(record.id)) {
- // if the main record is new, link the subrecord to it
- commands[fieldName].push(x2ManyCommands.link_to(relRecord.res_id));
- }
if (!_.isEmpty(changes)) {
commands[fieldName].push(x2ManyCommands.update(relRecord.res_id, changes));
}
@@ -4014,6 +3955,76 @@ var BasicModel = AbstractModel.extend({
});
},
/**
+ * Reload all data for a given resource
+ *
+ * @private
+ * @param {string} id local id for a resource
+ * @param {Object} [options]
+ * @param {boolean} [options.keepChanges=false] if true, doesn't discard the
+ * changes on the record before reloading it
+ * @returns {Deferred<string>} resolves to the id of the resource
+ */
+ _reload: function (id, options) {
+ options = options || {};
+ var element = this.localData[id];
+
+ if (element.type === 'record') {
+ if (!options.currentId && (('currentId' in options) || this.isNew(id))) {
+ var params = {
+ context: element.context,
+ fieldsInfo: element.fieldsInfo,
+ fields: element.fields,
+ viewType: element.viewType,
+ };
+ return this._makeDefaultRecord(element.model, params);
+ }
+ if (!options.keepChanges) {
+ this.discardChanges(id, {rollback: false});
+ }
+ } else if (element._changes) {
+ delete element.tempLimitIncrement;
+ _.each(element._changes, function (change) {
+ delete change.isNew;
+ });
+ }
+
+ if (options.context !== undefined) {
+ element.context = options.context;
+ }
+ if (options.domain !== undefined) {
+ element.domain = options.domain;
+ }
+ if (options.groupBy !== undefined) {
+ element.groupedBy = options.groupBy;
+ }
+ if (options.limit !== undefined) {
+ element.limit = options.limit;
+ }
+ if (options.offset !== undefined) {
+ this._setOffset(element.id, options.offset);
+ }
+ if (options.loadMoreOffset !== undefined) {
+ element.loadMoreOffset = options.loadMoreOffset;
+ } else {
+ // reset if not specified
+ element.loadMoreOffset = 0;
+ }
+ if (options.currentId !== undefined) {
+ element.res_id = options.currentId;
+ }
+ if (options.ids !== undefined) {
+ element.res_ids = options.ids;
+ element.count = element.res_ids.length;
+ }
+ if (element.type === 'record') {
+ element.offset = _.indexOf(element.res_ids, element.res_id);
+ }
+ var loadOptions = _.pick(options, 'fieldNames', 'viewType');
+ return this._load(element, loadOptions).then(function (result) {
+ return result.id;
+ });
+ },
+ /**
* Allows to save a value in the specialData cache associated to a given
* record and fieldName. If the value in the cache was already the given
* one, nothing is done and the method indicates it by returning false