diff options
| author | Khoi Nguyen <bng@odoo.com> | 2017-08-03 09:25:16 +0200 |
|---|---|---|
| committer | Khoi Nguyen <bng@odoo.com> | 2017-08-04 11:31:58 +0200 |
| commit | c300e5ede781f16b7d00cdcbc6bad227b265dd6b (patch) | |
| tree | f2692078bb6dd4301809531a1059ae338e4750a8 /addons/web/static/src/js | |
| parent | d19671f0d0ff7189055cbe0794afed32f8a387e6 (diff) | |
[FIX] web: reload right record when editing a many2one inside an x2many
Before this revision, editing a many2one inside an x2many field did not
cause an update of the x2many field upon saving. This is due to the fact
that a field on a screen was deemed affected by a record change only if
its value or a directly related record has been updated.
This present revision looks for changes recursively, thereby including
the case where an x2many field contains a many2one.
The bug appeared for example in Manufacturing, when editing the product
name of a BOM line.
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/views/form/form_controller.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index fa84f11df7f..7ddd3d16587 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -217,7 +217,7 @@ var FormController = BasicController.extend({ * * @private * @override method from field manager mixin - * @param {string} id + * @param {string} id - id of the previously changed record * @returns {Deferred} */ _confirmSave: function (id) { @@ -228,15 +228,21 @@ var FormController = BasicController.extend({ return this._setMode('readonly'); } } else { - // a subrecord changed, so update the corresponding relational field + // A subrecord has changed, so update the corresponding relational field // i.e. the one whose value is a record with the given id or a list // having a record with the given id in its data var record = this.model.get(this.handle); - var fieldsChanged = _.findKey(record.data, function (d) { - return _.isObject(d) && - (d.id === id || _.findWhere(d.data, {id: id})); - }); - return this.renderer.confirmChange(record, record.id, [fieldsChanged]); + + // Callback function which returns true + // if a value recursively contains a record with the given id. + // This will be used to determine the list of fields to reload. + var containsChangedRecord = function (value) { + return _.isObject(value) && + (value.id === id || _.find(value.data, containsChangedRecord)); + }; + + var changedFields = _.findKey(record.data, containsChangedRecord); + return this.renderer.confirmChange(record, record.id, [changedFields]); } }, /** |
