-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] sale: search panel improvements
Preparing the sales catalog to odoo 17 release: - some functional additions/improvements: - only attributes related to products currently visible are visible, - duplication of attributes names in the search panel is solved. task-3367295 closes odoo#126796 Signed-off-by: Valentin Chevalier <vcr@odoo.com>
- Loading branch information
1 parent
d896932
commit 32e4724
Showing
4 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
addons/sale/static/src/js/product_catalog/search/search_panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** @odoo-module **/ | ||
|
||
import { SearchPanel } from "@web/search/search_panel/search_panel"; | ||
import { useState } from "@odoo/owl"; | ||
|
||
|
||
export class ProductCatalogSearchPanel extends SearchPanel { | ||
setup() { | ||
super.setup(); | ||
|
||
this.state = useState({ | ||
...this.state, | ||
sectionOfAttributes: {}, | ||
}); | ||
} | ||
|
||
updateActiveValues() { | ||
super.updateActiveValues(); | ||
this.state.sectionOfAttributes = this.buildSection(); | ||
} | ||
|
||
buildSection() { | ||
const values = this.env.searchModel.filters[0].values; | ||
let sections = new Map(); | ||
|
||
values.forEach(element => { | ||
const name = element.display_name; | ||
const id = element.id; | ||
const count = element.__count; | ||
|
||
if (sections.has(name)) { | ||
let currentAttr = sections.get(name); | ||
currentAttr.get('ids').push(id); | ||
currentAttr.set('count', currentAttr.get('count') + count); | ||
} else { | ||
let newAttr = new Map(); | ||
newAttr.set('ids', [id]); | ||
newAttr.set('count', count); | ||
sections.set(name, newAttr); | ||
} | ||
}); | ||
|
||
return sections; | ||
} | ||
|
||
toggleSectionFilterValue(filterId, attrIds, { currentTarget }) { | ||
attrIds.forEach(id => { | ||
this.toggleFilterValue(filterId, id, { currentTarget }); | ||
}) | ||
} | ||
} | ||
|
||
ProductCatalogSearchPanel.subTemplates = { | ||
...SearchPanel.subTemplates, | ||
filtersGroup: "sale.ProductCatalogSearchPanel.FiltersGroup", | ||
} |
28 changes: 28 additions & 0 deletions
28
addons/sale/static/src/js/product_catalog/search/search_panel.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<templates id="template" xml:space="preserve"> | ||
<t t-name="sale.ProductCatalogSearchPanel.FiltersGroup" t-inherit="web.SearchPanel.FiltersGroup" t-inherit-mode="primary"> | ||
<li t-foreach="[...values.keys()]" position="replace"> | ||
<li t-foreach="[...this.state.sectionOfAttributes.keys()]" t-as="attrName" t-key="attrName" | ||
class="o_search_panel_filter_value list-group-item p-0 mb-1 border-0 o_cursor_pointer" | ||
t-att-class="{ 'ps-2' : isChildList }"> | ||
<t t-set="attrCount" t-value="this.state.sectionOfAttributes.get(attrName).get('count')"/> | ||
<t t-set="attrIds" t-value="this.state.sectionOfAttributes.get(attrName).get('ids')"/> | ||
<div class="form-check w-100"> | ||
<input type="checkbox" | ||
t-attf-id="{{ section.id }}_input_{{ attrName }}" | ||
class="form-check-input" | ||
t-on-click="ev => this.toggleSectionFilterValue(section.id, attrIds, ev)"/> | ||
<label class="o_search_panel_label form-check-label d-flex align-items-center justify-content-between w-100 o_cursor_pointer" | ||
t-attf-for="{{ section.id }}_input_{{ attrName }}" | ||
t-att-title="(group and group.tooltip) or false"> | ||
<span class="o_search_panel_label_title text-truncate" t-esc="attrName"/> | ||
<span t-if="section.enableCounters and attrCount gt 0" | ||
class="o_search_panel_counter text-muted mx-2 small" | ||
t-esc="attrCount"/> | ||
</label> | ||
</div> | ||
</li> | ||
</li> | ||
</t> | ||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters