feat: persistent hidden categories with wizard and toggle
Categories to hide are stored on woo.instance and persist across sessions. Click 'Hidden (N)' button to open wizard where you can add/remove categories using a tag picker. Eye/eye-slash toggle to quickly apply or unapply the filter without losing the saved list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,9 +61,8 @@ export class ProductMapping extends Component {
|
||||
pageSize: 50,
|
||||
|
||||
// Category filters
|
||||
odooCategories: [],
|
||||
odooFilterCategoryId: false,
|
||||
odooExcludeCategoryIds: [],
|
||||
categoryFilterActive: true,
|
||||
excludedCategoryCount: 0,
|
||||
|
||||
// Conflicts tab
|
||||
conflicts: [],
|
||||
@@ -71,7 +70,7 @@ export class ProductMapping extends Component {
|
||||
|
||||
onWillStart(async () => {
|
||||
await this._loadInstances();
|
||||
await this._loadOdooCategories();
|
||||
await this._loadExcludedCategoryCount();
|
||||
await this._refreshAll();
|
||||
});
|
||||
}
|
||||
@@ -131,12 +130,23 @@ export class ProductMapping extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
async _loadOdooCategories() {
|
||||
async _loadExcludedCategoryCount() {
|
||||
if (!this.state.instanceId) {
|
||||
this.state.excludedCategoryCount = 0;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await rpc("/woo/search/odoo_categories", {});
|
||||
this.state.odooCategories = result || [];
|
||||
const result = await rpc("/web/dataset/call_kw", {
|
||||
model: "woo.instance",
|
||||
method: "read",
|
||||
args: [[this.state.instanceId], ["excluded_category_ids"]],
|
||||
kwargs: {},
|
||||
});
|
||||
if (result && result[0]) {
|
||||
this.state.excludedCategoryCount = (result[0].excluded_category_ids || []).length;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[ProductMapping] _loadOdooCategories error:", err);
|
||||
console.error("[ProductMapping] _loadExcludedCategoryCount error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,11 +160,9 @@ export class ProductMapping extends Component {
|
||||
if (this.state.instanceId) {
|
||||
params.instance_id = this.state.instanceId;
|
||||
}
|
||||
if (this.state.odooFilterCategoryId) {
|
||||
params.category_id = this.state.odooFilterCategoryId;
|
||||
}
|
||||
if (this.state.odooExcludeCategoryIds.length) {
|
||||
params.exclude_category_ids = JSON.stringify(this.state.odooExcludeCategoryIds);
|
||||
// Pass excluded categories if filter is active
|
||||
if (this.state.categoryFilterActive && this.state.instanceId) {
|
||||
params.apply_excluded = true;
|
||||
}
|
||||
const result = await rpc("/woo/search/odoo_products", params);
|
||||
this.state.odooProducts = (result && result.results) || [];
|
||||
@@ -285,34 +293,28 @@ export class ProductMapping extends Component {
|
||||
// Category filter
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
async onOdooCategoryFilter(ev) {
|
||||
const val = ev.target.value;
|
||||
this.state.odooFilterCategoryId = val ? parseInt(val, 10) : false;
|
||||
this.state.unmatchedOdooPage = 1;
|
||||
await this._loadOdooProducts("");
|
||||
}
|
||||
|
||||
toggleExcludeCategory(catId) {
|
||||
const idx = this.state.odooExcludeCategoryIds.indexOf(catId);
|
||||
if (idx >= 0) {
|
||||
this.state.odooExcludeCategoryIds.splice(idx, 1);
|
||||
} else {
|
||||
this.state.odooExcludeCategoryIds.push(catId);
|
||||
async openCategoryFilter() {
|
||||
if (!this.state.instanceId) {
|
||||
this.notification.add("Select an instance first.", { type: "warning" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async applyExcludeCategories() {
|
||||
await this.actionService.doAction({
|
||||
type: 'ir.actions.act_window',
|
||||
res_model: 'woo.category.filter',
|
||||
views: [[false, 'form']],
|
||||
target: 'new',
|
||||
context: {
|
||||
default_instance_id: this.state.instanceId,
|
||||
},
|
||||
});
|
||||
// Reload after wizard closes
|
||||
await this._loadExcludedCategoryCount();
|
||||
this.state.unmatchedOdooPage = 1;
|
||||
await this._loadOdooProducts("");
|
||||
}
|
||||
|
||||
isCategoryExcluded(catId) {
|
||||
return this.state.odooExcludeCategoryIds.includes(catId);
|
||||
}
|
||||
|
||||
async clearCategoryFilter() {
|
||||
this.state.odooFilterCategoryId = false;
|
||||
this.state.odooExcludeCategoryIds = [];
|
||||
async toggleCategoryFilter() {
|
||||
this.state.categoryFilterActive = !this.state.categoryFilterActive;
|
||||
this.state.unmatchedOdooPage = 1;
|
||||
await this._loadOdooProducts("");
|
||||
}
|
||||
|
||||
@@ -336,18 +336,20 @@
|
||||
<div class="woo-split-panel-header" style="flex-wrap: wrap; gap: 6px;">
|
||||
<span>Odoo Products</span>
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<select class="woo-filter-select" t-on-change="onOdooCategoryFilter">
|
||||
<option value="">All Categories</option>
|
||||
<t t-foreach="state.odooCategories" t-as="cat" t-key="cat.id">
|
||||
<option t-att-value="cat.id"
|
||||
t-att-selected="state.odooFilterCategoryId === cat.id">
|
||||
<t t-esc="cat.complete_name"/>
|
||||
</option>
|
||||
<button class="woo-btn woo-btn-secondary woo-btn-sm"
|
||||
t-on-click="openCategoryFilter"
|
||||
title="Manage hidden categories">
|
||||
<i class="fa fa-filter me-1"/>
|
||||
Hidden
|
||||
<t t-if="state.excludedCategoryCount">
|
||||
(<t t-esc="state.excludedCategoryCount"/>)
|
||||
</t>
|
||||
</select>
|
||||
<t t-if="state.odooFilterCategoryId || state.odooExcludeCategoryIds.length">
|
||||
<button class="woo-btn-icon" title="Clear filter" t-on-click="clearCategoryFilter">
|
||||
<i class="fa fa-times"/>
|
||||
</button>
|
||||
<t t-if="state.excludedCategoryCount">
|
||||
<button t-att-class="'woo-btn woo-btn-sm ' + (state.categoryFilterActive ? 'woo-btn-primary' : 'woo-btn-secondary')"
|
||||
t-on-click="toggleCategoryFilter"
|
||||
t-att-title="state.categoryFilterActive ? 'Filter active — click to show all' : 'Filter off — click to hide categories'">
|
||||
<i t-att-class="'fa ' + (state.categoryFilterActive ? 'fa-eye-slash' : 'fa-eye')"/>
|
||||
</button>
|
||||
</t>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user