[IMP] website{_event}: show event location in search bar

Currently, if a user searches for an event based on a location name, the
location name is not displayed.

This commit shows the event location name when users search for the event.
Also add the "_getFieldsNames" method to easily override this method to
add a field name from another model.

task-2791031

Part-of: odoo/odoo#89796
This commit is contained in:
Mahamadasif Ansari
2023-04-05 09:42:23 +02:00
committed by Sahil Patel
parent 50d6f18250
commit eb132590db
5 changed files with 53 additions and 9 deletions
@@ -120,14 +120,7 @@ publicWidget.registry.searchBar = publicWidget.Widget.extend({
'options': this.options,
},
});
const fieldNames = [
'name',
'description',
'extra_link',
'detail',
'detail_strike',
'detail_extra',
];
const fieldNames = this._getFieldsNames();
res.results.forEach(record => {
for (const fieldName of fieldNames) {
if (record[fieldName]) {
@@ -205,6 +198,16 @@ publicWidget.registry.searchBar = publicWidget.Widget.extend({
$prevMenu.remove();
}
},
_getFieldsNames() {
return [
'description',
'detail',
'detail_extra',
'detail_strike',
'extra_link',
'name',
];
},
//--------------------------------------------------------------------------
// Handlers
+3 -1
View File
@@ -63,6 +63,7 @@ class Event(models.Model):
location_menu_ids = fields.One2many(
"website.event.menu", "event_id", string="Location Menus",
domain=[("menu_type", "=", "location_menu")])
address_name = fields.Char(related='address_id.name')
register_menu = fields.Boolean(
"Register Menu", compute="_compute_website_menu_data",
readonly=False, store=True)
@@ -516,10 +517,11 @@ class Event(models.Model):
current_date = date_details[1]
search_fields = ['name']
fetch_fields = ['name', 'website_url']
fetch_fields = ['name', 'website_url', 'address_name']
mapping = {
'name': {'name': 'name', 'type': 'text', 'match': True},
'website_url': {'name': 'website_url', 'type': 'text', 'truncate': False},
'address_name': {'name': 'address_name', 'type': 'text', 'match': True},
}
if with_description:
search_fields.append('subtitle')
@@ -0,0 +1,13 @@
/** @odoo-module **/
import publicWidget from 'web.public.widget';
publicWidget.registry.searchBar.include({
/**
*
* @override
*/
_getFieldsNames() {
return [...this._super(), 'address_name'];
}
});
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve">
<t t-inherit="website.s_searchbar.autocomplete" t-inherit-mode="extension">
<xpath expr="//div[@class='o_search_result_item_detail px-3']" position="inside">
<span t-if="result['address_name']" class="small">
<span class="fa fa-map-marker"/> <t t-out="result['address_name']"/>
</span>
</xpath>
</t>
</templates>
@@ -85,4 +85,16 @@
</xpath>
</template>
<record id="website_event.s_searchbar_000_js" model="ir.asset">
<field name="name">Searchbar 000 JS</field>
<field name="bundle">web.assets_frontend</field>
<field name="path">website_event/static/src/snippets/s_searchbar/000.js</field>
</record>
<record id="website_event.s_searchbar_000_xml" model="ir.asset">
<field name="name">Searchbar 000 XML</field>
<field name="bundle">web.assets_frontend</field>
<field name="path">website_event/static/src/snippets/s_searchbar/000.xml</field>
</record>
</odoo>