From aef6a5aaed22b250799ce92b5021d240fed9e12e Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 5 Feb 2019 11:56:29 +0000 Subject: [PATCH] [FIX] website: specific view ID might also change on save Commit https://github.com/odoo/odoo/commit/29075a8e2c734624cec4f6009185616634f70dea was written while there was an incorrect behavior related to multi-website, oe_structure_ID and edit mode in a rare specific case (see the second commit from this PR for detailed explanation https://github.com/odoo/odoo/pull/30834). That rare case was detected in 12.0 since the tour did not work on master with the new editor (that fixed the incorrect behavior). Basically, it was COWing the edited view even if only an oe_structure_ID was touched. Indeed, when saving a specific view in the HTML editor, we should also search for its possible new ID as it could change if we also edited its generic parent. In that case, the view will be copied and then unlinked to preserve inherit order on the new specific tree. --- addons/website/static/src/js/widgets/ace.js | 33 +++++++++++---------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/addons/website/static/src/js/widgets/ace.js b/addons/website/static/src/js/widgets/ace.js index f4fe74ddd38..449549264a8 100644 --- a/addons/website/static/src/js/widgets/ace.js +++ b/addons/website/static/src/js/widgets/ace.js @@ -40,23 +40,24 @@ var WebsiteAceEditor = AceEditor.extend({ return this._super.apply(this, arguments).then((function () { var defs = []; if (this.currentType === 'xml') { + // When saving a view, the view ID might change. Thus, the + // active ID in the URL will be incorrect. After the save + // reload, that URL ID won't be found and JS will crash. + // We need to find the new ID (either because the view became + // specific or because its parent was edited too and the view + // got copy/unlink). var selectedView = _.findWhere(this.views, {id: this._getSelectedResource()}); - if (!selectedView.website_id[0]) { - // When saving a generic view, the view will be COW'd and - // replace by the specific view after the reload. Thus the id in - // URL won't exist anymore. We need to find the specific ID. - var context = weContext.get(); - defs.push(this._rpc({ - model: 'ir.ui.view', - method: 'search_read', - fields: ['id'], - domain: [['key', '=', selectedView.key], ['website_id', '=', context.website_id]], - }).then((function (view) { - if (view[0]) { - this._updateHash(view[0].id); - } - }).bind(this))); - } + var context = weContext.get(); + defs.push(this._rpc({ + model: 'ir.ui.view', + method: 'search_read', + fields: ['id'], + domain: [['key', '=', selectedView.key], ['website_id', '=', context.website_id]], + }).then((function (view) { + if (view[0]) { + this._updateHash(view[0].id); + } + }).bind(this))); } return $.when.apply($, defs).then((function () { window.location.reload();