diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-04-05 22:34:10 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 7e14e819038bb3eccaebb781790c0c58f07f1c64 (patch) | |
| tree | 756604ae76e2222782d17af7826dceaa2d42ecfd /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | e8b9515980997884c2099cbed3e71a5a0120b9d0 (diff) | |
[FIX] web: one2many onchanges
When there is an onchange on fields of a one2many, the data given
to the onchange RPC should contain an additional key for the
corresponding many2one, mapping to the current data of the parent
(main) record.
This wasn't working before this rev. for new o2m records created
when the one2many wasn't editable inline (with a list view
editable), because in that particular case, the reference to the
parent record wasn't specified correctly.
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.js | 48 |
1 files changed, 30 insertions, 18 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 c71ac81e0d9..1f8d5ce94c6 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -162,7 +162,6 @@ var BasicModel = AbstractModel.extend({ fields: list.fields, fieldsInfo: list.fieldsInfo, parentID: list.id, - relationField: list.relationField, viewType: list.viewType, }; return this._makeDefaultRecord(list.model, params).then(function (id) { @@ -863,22 +862,7 @@ var BasicModel = AbstractModel.extend({ var onchange_spec = this._buildOnchangeSpecs(record); var idList = record.data.id ? [record.data.id] : []; var context = this._getContext(record); - - var rawData = this.get(record.id, {raw: true}).data; - var commands = this._generateX2ManyCommands(record, false); - - // compute field values - var fieldNames = record.getFieldNames(); - var currentData = _.pick(_.extend(rawData, commands), fieldNames); - if (record.relationField) { - // if there is a relation field, this means that record is an elem - // in a one2many. The relation field is the corresponding many2one - - // parent is the list element containing all the records in the o2m - // and parent.parentID is the ID of the main record - var parent = this.localData[record.parentID]; - currentData[record.relationField] = this.get(parent.parentID, {raw:true}).data; - } + var currentData = this._generateOnChangeData(record); if (fields.length === 1) { fields = fields[0]; @@ -940,6 +924,7 @@ var BasicModel = AbstractModel.extend({ fields: list.fields, fieldsInfo: list.fieldsInfo, modelName: list.model, + parentID: list.id, viewType: list.viewType, }; if (command[0] === 1) { @@ -1660,6 +1645,34 @@ var BasicModel = AbstractModel.extend({ return changes; }, /** + * Generates an object mapping field names to their current value in a given + * record. If the record is inside a one2many, the returned object contains + * an additional key (the corresponding many2one field name) mapping to the + * current value of the parent record. + * + * @param {Object} record + * @returns {Object} the data + */ + _generateOnChangeData: function (record) { + var commands = this._generateX2ManyCommands(record, false); + var data = _.extend(this.get(record.id, {raw: true}).data, commands); + + // one2many records have a parentID + if (record.parentID) { + var parent = this.localData[record.parentID]; + // parent is the list element containing all the records in the + // one2many and parent.parentID is the ID of the main record + // if there is a relation field, this means that record is an elem + // in a one2many. The relation field is the corresponding many2one + if (parent.parentID && parent.relationField) { + var parentRecord = this.localData[parent.parentID]; + data[parent.relationField] = this._generateOnChangeData(parentRecord); + } + } + + return data; + }, + /** * Read all x2many fields and generate the commands for the server to create * or write them... * @@ -1992,7 +2005,6 @@ var BasicModel = AbstractModel.extend({ fieldsInfo: params.fieldsInfo, context: params.context, parentID: params.parentID, - relationField: params.relationField, res_ids: params.res_ids, viewType: params.viewType, }); |
