summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-06-14 13:42:38 +0200
committerAaron Bohy <aab@odoo.com>2017-06-15 08:39:50 +0200
commitf6525c6b6ce04534e7fb2c282191243b8d3c4707 (patch)
tree1754c87fdce5df8fa98fa6501edd28c64f4dc282 /addons/web/static/src/js/views/basic/basic_model.js
parent86cf4f41b70bf186b59d3aeafe09725da9a15fd1 (diff)
[FIX] web: BasicModel: onchanges: send all values
Since commit ebd17217c4, values of readonly fields inside x2many fields weren't sent for onchanges, whereas they should. This was for example an issue on the stock.picking form view (which is in state 'draft' by default). If the user added a stock.move, the state field on the move wasn't sent for the onchange, and thus the state field on the picking was set to false.
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.js42
1 files changed, 28 insertions, 14 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 ae48a98dd13..d897a74c696 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -736,7 +736,7 @@ var BasicModel = AbstractModel.extend({
// id never changes, and should not be written
delete record._changes.id;
}
- var changes = self._generateChanges(record, options.viewType);
+ var changes = self._generateChanges(record, {viewType: options.viewType});
if (method === 'create') {
var fieldNames = record.getFieldNames();
@@ -1877,18 +1877,28 @@ var BasicModel = AbstractModel.extend({
*
* @private
* @param {Object} record
- * @param {string} [viewType] current viewType. If not set, we will assume
- * main viewType from the record. Note that if an editionViewType is
+ * @param {Object} [options]
+ * @param {boolean} [options.changesOnly=true] if true, only generates
+ * commands for fields that have changed (concerns x2many fields only)
+ * @param {boolean} [options.withReadonly=false] if false, doesn't generate
+ * changes for readonly fields
+ * @param {string} [options.viewType] current viewType. If not set, we will
+ * assume main viewType from the record. Note that if an editionViewType is
* specified for a field, it will take the priority over the viewType arg.
* @returns {Object} a map from changed fields to their new value
*/
- _generateChanges: function (record, viewType) {
- viewType = viewType || record.viewType;
+ _generateChanges: function (record, options) {
+ options = options || {};
+ var viewType = options.viewType || record.viewType;
var changes = _.extend({}, record._changes);
- var commands = this._generateX2ManyCommands(record, true);
+ var withReadonly = options.withReadonly || false;
+ var commands = this._generateX2ManyCommands(record, {
+ changesOnly: 'changesOnly' in options ? options.changesOnly : true,
+ withReadonly: withReadonly,
+ });
for (var fieldName in record.fields) {
// remove readonly fields from the list of changes
- if (fieldName in changes || fieldName in commands) {
+ if (!withReadonly && fieldName in changes || fieldName in commands) {
var editionViewType = record._editionViewType[fieldName] || viewType;
if (this._isFieldReadonly(record, fieldName, editionViewType)) {
delete changes[fieldName];
@@ -1923,7 +1933,7 @@ var BasicModel = AbstractModel.extend({
* @returns {Object} the data
*/
_generateOnChangeData: function (record) {
- var commands = this._generateX2ManyCommands(record, false);
+ var commands = this._generateX2ManyCommands(record, {withReadonly: true});
var data = _.extend(this.get(record.id, {raw: true}).data, commands);
// one2many records have a parentID
@@ -1946,12 +1956,16 @@ var BasicModel = AbstractModel.extend({
* or write them...
*
* @param {Object} record
+ * @param {Object} [options]
* @param {boolean} [changesOnly=false] if true, only generates commands for
* fields that have changed
+ * @param {boolean} [options.withReadonly=false] if false, doesn't generate
+ * changes for readonly fields in commands
* @returns {Object} a map from some field names to commands
*/
- _generateX2ManyCommands: function (record, changesOnly) {
+ _generateX2ManyCommands: function (record, options) {
var self = this;
+ options = options || {};
var commands = {};
var data = _.extend({}, record.data, record._changes);
var type;
@@ -1965,7 +1979,7 @@ var BasicModel = AbstractModel.extend({
continue;
}
var list = this.localData[data[fieldName]];
- if (changesOnly && !list._changes) {
+ if (options.changesOnly && !list._changes) {
// if only changes are requested, skip if there is no change
continue;
}
@@ -1983,7 +1997,7 @@ var BasicModel = AbstractModel.extend({
// generate update commands for records that have been
// updated (it may happen with editable lists)
_.each(relData, function (relRecord) {
- var changes = self._generateChanges(relRecord);
+ var changes = self._generateChanges(relRecord, options);
if (!_.isEmpty(changes)) {
var command = x2ManyCommands.update(relRecord.res_id, changes);
commands[fieldName].push(command);
@@ -2002,7 +2016,7 @@ var BasicModel = AbstractModel.extend({
if (_.contains(keptIds, relIds[i])) {
// this is an id that already existed
relRecord = _.findWhere(relData, {res_id: relIds[i]});
- changes = this._generateChanges(relRecord);
+ changes = this._generateChanges(relRecord, options);
if (!_.isEmpty(changes)) {
command = x2ManyCommands.update(relRecord.res_id, changes);
didChange = true;
@@ -2013,11 +2027,11 @@ var BasicModel = AbstractModel.extend({
} else if (_.contains(addedIds, relIds[i])) {
// this is a new id
relRecord = _.findWhere(relData, {res_id: relIds[i]});
- changes = this._generateChanges(relRecord);
+ changes = this._generateChanges(relRecord, options);
commands[fieldName].push(x2ManyCommands.create(changes));
}
}
- if (changesOnly && !didChange && addedIds.length === 0 && removedIds.length === 0) {
+ if (options.changesOnly && !didChange && addedIds.length === 0 && removedIds.length === 0) {
// in this situation, we have no changed ids, no added
// ids and no removed ids, so we can safely ignore the
// last changes