From 479c616b8d52e48266f8f06ed56155587f0bf269 Mon Sep 17 00:00:00 2001 From: Patrick Hoste Date: Tue, 10 Jan 2023 12:52:29 +0000 Subject: [PATCH] [IMP] website_event: change snippet tag options to fakem2m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit changes the event snippet tag option which was misconfigured. Using the option fakem2m is indeed the way to go to filter the events based on the given tags. This commit also changes the way the domain works with tags: tags from the same category will apply an OR condition between them and tags from a different category will apply an AND condition. Task-3105126 closes odoo/odoo#109538 Signed-off-by: Warnon Aurélien (awa) --- .../static/src/snippets/s_events/000.js | 13 ++++---- .../static/src/snippets/s_events/options.js | 33 ------------------- .../website_event/views/snippets/s_events.xml | 7 ++-- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/addons/website_event/static/src/snippets/s_events/000.js b/addons/website_event/static/src/snippets/s_events/000.js index 68fae94a2ab..bde61630864 100644 --- a/addons/website_event/static/src/snippets/s_events/000.js +++ b/addons/website_event/static/src/snippets/s_events/000.js @@ -12,12 +12,13 @@ const DynamicSnippetEvents = DynamicSnippet.extend({ * @private */ _getSearchDomain: function () { - const searchDomain = this._super.apply(this, arguments); - const filterByTagIds = JSON.parse(this.$el.get(0).dataset.filterByTagIds || '[]'); - if (filterByTagIds.length > 0) { - searchDomain.concat(Array(filterByTagIds.length-1).fill('&')); - for (const tag of filterByTagIds) { - searchDomain.push(['tag_ids', 'in', tag]); + let searchDomain = this._super.apply(this, arguments); + const filterByTagIds = this.$el.get(0).dataset.filterByTagIds; + if (filterByTagIds) { + let tagGroupedByCategory = _.groupBy(JSON.parse(filterByTagIds), 'category_id'); + for (const category in tagGroupedByCategory) { + searchDomain = searchDomain.concat( + [['tag_ids', 'in', tagGroupedByCategory[category].map(e => e.id)]]); } } return searchDomain; diff --git a/addons/website_event/static/src/snippets/s_events/options.js b/addons/website_event/static/src/snippets/s_events/options.js index 9bbe76d5b7c..d5c9ada707c 100644 --- a/addons/website_event/static/src/snippets/s_events/options.js +++ b/addons/website_event/static/src/snippets/s_events/options.js @@ -10,39 +10,6 @@ const dynamicSnippetEventOptions = dynamicSnippetOptions.extend({ init() { this._super.apply(this, arguments); this.modelNameFilter = 'event.event'; - this.tagIDs = []; - }, - - async willStart() { - const _super = this._super.bind(this); - this.tagIDs = JSON.parse(this.$target[0].dataset.filterByTagIds || '[]'); - const tags = await this._rpc({ - model: 'event.tag', - method: 'search_read', - domain: ['&', ['category_id.website_published', '=', true], ['color', 'not in', ['0', false]]], - fields: ['id', 'display_name'], - }); - this.allTagsByID = {}; - for (const tag of tags) { - this.allTagsByID[tag.id] = tag; - } - - return _super(...arguments); - }, - - setTags(previewMode, widgetValue, params) { - this.tagIDs = JSON.parse(widgetValue).map(tag => tag.id); - this.selectDataAttribute(previewMode, JSON.stringify(this.tagIDs), params); - }, - - /** - * @override - */ - async _computeWidgetState(methodName, params) { - if (methodName === 'setTags') { - return JSON.stringify(this.tagIDs.map(id => this.allTagsByID[id])); - } - return this._super(...arguments); }, _setOptionsDefaultValues() { diff --git a/addons/website_event/views/snippets/s_events.xml b/addons/website_event/views/snippets/s_events.xml index f81151a3e69..e883f41cec5 100644 --- a/addons/website_event/views/snippets/s_events.xml +++ b/addons/website_event/views/snippets/s_events.xml @@ -83,12 +83,13 @@