From 0aa300785a90655d8eca78a2b26bc724baa2aafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Hennecart=20=28jeh=29?= Date: Wed, 17 Aug 2022 12:38:27 +0000 Subject: [PATCH] [FIX] website_event: fix frontend track edition When editing a field on a track, a traceback was raised because the fields website_menu and website_url are not present in the event.track model. Now we always use the event.event model and we get the event object id from the url. We also set the url as the current one to stay on the same page after reloading it. task-2942617 closes odoo/odoo#102545 X-original-commit: 5f1f082dbe268522f8fc7e63ad5f564b25020a22 Signed-off-by: Thibault Delavallee (tde) --- .../static/src/snippets/options.js | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/addons/website_event/static/src/snippets/options.js b/addons/website_event/static/src/snippets/options.js index 8e3ac35da91..c1f796b0e3a 100644 --- a/addons/website_event/static/src/snippets/options.js +++ b/addons/website_event/static/src/snippets/options.js @@ -9,21 +9,19 @@ options.registry.WebsiteEvent = options.Class.extend({ */ async start() { const res = await this._super(...arguments); - const eventObject = this._getEventObject(); - this.modelName = eventObject.model; - this.eventId = eventObject.id; + this.currentWebsiteUrl = this.ownerDocument.location.pathname; + this.eventId = this._getEventObjectId(); // Only need for one RPC request as the option will be destroyed if a // change is made. const rpcData = await this._rpc({ - model: this.modelName, + model: 'event.event', method: 'read', args: [ [this.eventId], - ['website_menu', 'website_url'], + ['website_menu'], ], }); - this.eventUrl = rpcData[0]['website_url']; - this.data.reload = this.eventUrl; + this.data.reload = this.currentWebsiteUrl; this.websiteMenu = rpcData[0]['website_menu']; return res; }, @@ -37,7 +35,7 @@ options.registry.WebsiteEvent = options.Class.extend({ */ displaySubmenu(previewMode, widgetValue, params) { return this._rpc({ - model: this.modelName, + model: 'event.event', method: 'toggle_website_menu', args: [[this.eventId], widgetValue], }); @@ -59,14 +57,12 @@ options.registry.WebsiteEvent = options.Class.extend({ return this._super(...arguments); }, /** + * Ensure that we get the event object id as we could be inside a sub-object of the event + * like an event.track * @private */ - _getEventObject() { - const repr = this.ownerDocument.documentElement.dataset.mainObject; - const m = repr.match(/(.+)\((\d+),(.*)\)/); - return { - model: m[1], - id: m[2] | 0, - }; + _getEventObjectId() { + const objectIds = this.currentWebsiteUrl.match(/(?<=-)\d+(?![-\w\d])/); + return parseInt(objectIds[0]) | 0; }, });