From 609e25521eb4da58ba5b838c1b8db24b6eb419e2 Mon Sep 17 00:00:00 2001 From: "Guillaume (gdi)" Date: Tue, 23 May 2023 08:03:30 +0000 Subject: [PATCH] [FIX] web_editor: clear m2X cache This commit clears the cache of we-many2X widgets. Since [the merge of the backend into the frontend], the page is not refreshed when the user goes to modify data in his backend. This means that if the data has been changed between two editions of a page and the many2X widget has already made the RPC call, it will not do it again and will still have the old data. For example with website installed: - Edit a page of your website - Add the add to cart button - Search for "ERP" product - The product does not exist so save the page - Create and publish a new product called "ERP" - Edit the page again - Search for the product "ERP" => It is not present because the query is in the cache which has not been cleared. If you refresh the page, the product will be found. This commit fixes this problem by clearing the cache after an edit. Note that a similar implementation of caching clearing has been done here: https://github.com/odoo/odoo/commit/3efb726575679f62f9ee2894193323bfe45d7938 [the merge of the backend into the frontend]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b task-3078137 closes odoo/odoo#124908 X-original-commit: ff0cfca420a434e6024654749ea316bbfc5e0772 Signed-off-by: Romain Derie (rde) Signed-off-by: Dieleman Guillaume (gdi) --- addons/web_editor/static/src/js/editor/snippets.options.js | 7 ++++++- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index a0c694f6f91..1cc37cd3d74 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -2535,7 +2535,10 @@ const SelectPagerUserValueWidget = SelectUserValueWidget.extend({ } }); -const m2oRpcCache = {}; +let m2oRpcCache = {}; +const clearM2oRpcCache = () => { + m2oRpcCache = {}; +}; const Many2oneUserValueWidget = SelectUserValueWidget.extend({ className: (SelectUserValueWidget.prototype.className || '') + ' o_we_many2one', events: Object.assign({}, SelectUserValueWidget.prototype.events, { @@ -8206,4 +8209,6 @@ export default { // Other names for convenience Class: SnippetOptionWidget, registry: registry, + + clearM2oRpcCache, }; diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 60076f2e246..0ae769905e1 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -16,6 +16,7 @@ import { device } from "web.config"; import { localization } from "@web/core/l10n/localization"; import * as OdooEditorLib from "@web_editor/js/editor/odoo-editor/src/OdooEditor"; import snippetsEditor from "web_editor.snippet.editor"; +import snippetsOptions from "web_editor.snippets.options"; import Toolbar from "web_editor.toolbar"; import weWidgets from "wysiwyg.widgets"; import Link from "wysiwyg.widgets.Link"; @@ -746,6 +747,7 @@ const Wysiwyg = Widget.extend({ for (const timeout of this.tooltipTimeouts) { clearTimeout(timeout); } + snippetsOptions.clearM2oRpcCache(); this._super(); }, /**