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("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user