summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-10-11 08:55:03 +0200
committerGéry Debongnie <ged@odoo.com>2017-10-12 16:14:47 +0200
commit7d448d57e34511eb668a695e9238a2096c05411e (patch)
tree8ad81a7b984a73a5e163cc26a2609363ca3c3d75 /addons/web/static/src/js/views/basic
parentb44a482c53d7f09aa4d2068c8589cca6fe624e26 (diff)
[FIX] web: fix issue with default_get/onchange and one2many
Before this commit, there was a bug when creating a new record which contains a one2many with an onchange. The commands sent to the onchange did not contain the full information. Here is how you could reproduce the issue: install expense, go to the expense list view, select the 2 lines, then, in the 'action' menu in the control panel, choose 'Expense: submit to manager'. In the new expense sheet, you could see that there were two lines in the one2many expense_line_ids. However, these lines are empty. The reason is that the commands sent in the onchange were 2 commands 0, with {} as data. So, in short, the BasicModel did generate the proper commands, but with empty data, in the specific case when we have a non empty one2many in a default_get, then an onchange. To solve this issue, I had to fix 2 things: the internal data struture was wrongly updated, and the commands should be generated with all the data, and not only the changes.
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js29
1 files changed, 15 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 377ae7157d3..073d8599f06 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -2433,7 +2433,12 @@ var BasicModel = AbstractModel.extend({
_generateChanges: function (record, options) {
options = options || {};
var viewType = options.viewType || record.viewType;
- var changes = _.extend({}, record._changes);
+ var changes;
+ if ('changesOnly' in options && !options.changesOnly) {
+ changes = _.extend({}, record.data, record._changes);
+ } else {
+ changes = _.extend({}, record._changes);
+ };
var withReadonly = options.withReadonly || false;
var commands = this._generateX2ManyCommands(record, {
changesOnly: 'changesOnly' in options ? options.changesOnly : true,
@@ -2479,10 +2484,14 @@ var BasicModel = AbstractModel.extend({
* current value of the parent record.
*
* @param {Object} record
+ * @param {Object} [options] This option object will be given to the private
+ * method _generateX2ManyCommands. In particular, it is useful to be able
+ * to send changesOnly:true to get all data, not only the current changes.
* @returns {Object} the data
*/
- _generateOnChangeData: function (record) {
- var commands = this._generateX2ManyCommands(record, {withReadonly: true});
+ _generateOnChangeData: function (record, options) {
+ options = _.extend({}, options || {}, {withReadonly: true});
+ var commands = this._generateX2ManyCommands(record, options);
var data = _.extend(this.get(record.id, {raw: true}).data, commands);
// 'display_name' is automatically added to the list of fields to fetch,
// when fetching a record, even if it doesn't appear in the view. However,
@@ -2601,6 +2610,7 @@ var BasicModel = AbstractModel.extend({
relRecord = _.findWhere(relRecordUpdated, {res_id: list.res_ids[i]});
changes = relRecord ? this._generateChanges(relRecord, options) : {};
if (!_.isEmpty(changes)) {
+ delete changes.id;
command = x2ManyCommands.update(relRecord.res_id, changes);
didChange = true;
} else {
@@ -3170,16 +3180,7 @@ var BasicModel = AbstractModel.extend({
if (value[0] === 6) {
// REPLACE_WITH
_.each(value[2], function (res_id) {
- r = self._makeDataPoint({
- modelName: x2manyList.model,
- context: x2manyList.context,
- fieldsInfo: fieldsInfo,
- fields: fields,
- parentID: x2manyList.id,
- res_id: res_id,
- viewType: viewType,
- });
- x2manyList._changes.push({operation: 'ADD', id: r.id});
+ x2manyList._changes.push({operation: 'ADD', resID: res_id});
});
var def = self._readUngroupedList(x2manyList).then(function () {
return $.when(
@@ -3291,7 +3292,7 @@ var BasicModel = AbstractModel.extend({
options.fieldName = fields;
}
var context = this._getContext(record, options);
- var currentData = this._generateOnChangeData(record);
+ var currentData = this._generateOnChangeData(record, {changesOnly: false});
return self._rpc({
model: record.model,