[IMP] website_event: change snippet tag options to fakem2m
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) <awa@odoo.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -83,12 +83,13 @@
|
||||
<we-many2many t-if="snippet_name == 'event_upcoming_snippet'"
|
||||
string="Event Tags"
|
||||
data-name="event_tag_opt"
|
||||
data-model="event.event"
|
||||
data-m2o-field="tag_ids"
|
||||
data-model="event.tag"
|
||||
data-fakem2m="true"
|
||||
data-domain='[["category_id.website_published", "=", true], ["color", "not in", ["0", false]]]'
|
||||
data-limit="10"
|
||||
data-set-tags=""
|
||||
data-attribute-name="filterByTagIds"
|
||||
data-fields="["category_id"]"
|
||||
data-select-data-attribute=""
|
||||
data-no-preview="true"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user