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:
@@ -33,6 +33,7 @@
|
||||
'wizard/woo_setup_wizard_views.xml',
|
||||
'wizard/woo_product_fetch_views.xml',
|
||||
'wizard/woo_product_create_views.xml',
|
||||
'wizard/woo_category_filter_views.xml',
|
||||
],
|
||||
'assets': {
|
||||
'web.assets_backend': [
|
||||
|
||||
@@ -22,7 +22,8 @@ class WooProductSearchController(http.Controller):
|
||||
type='jsonrpc', auth='user', methods=['POST'],
|
||||
)
|
||||
def search_odoo_products(self, query='', instance_id=None, limit=20, offset=0,
|
||||
category_id=None, exclude_category_ids=None, **kw):
|
||||
category_id=None, exclude_category_ids=None,
|
||||
apply_excluded=False, **kw):
|
||||
"""
|
||||
Search Odoo products by name or internal reference (SKU).
|
||||
|
||||
@@ -61,6 +62,12 @@ class WooProductSearchController(http.Controller):
|
||||
if exclude_category_ids:
|
||||
domain.append(('categ_id', 'not in', [int(x) for x in exclude_category_ids]))
|
||||
|
||||
# Apply instance-level excluded categories
|
||||
if apply_excluded and instance_id:
|
||||
instance = request.env['woo.instance'].browse(int(instance_id))
|
||||
if instance.exists() and instance.excluded_category_ids:
|
||||
domain.append(('categ_id', 'not in', instance.excluded_category_ids.ids))
|
||||
|
||||
total = request.env['product.product'].search_count(domain)
|
||||
products = request.env['product.product'].search(domain, limit=limit, offset=offset)
|
||||
|
||||
|
||||
@@ -53,6 +53,10 @@ class WooInstance(models.Model):
|
||||
|
||||
# Category mapping
|
||||
category_map_ids = fields.One2many('woo.category.map', 'instance_id', string='Category Mappings')
|
||||
excluded_category_ids = fields.Many2many(
|
||||
'product.category', string='Hidden Categories',
|
||||
help='Products in these categories will be hidden from the unmatched products list.'
|
||||
)
|
||||
|
||||
# AI Configuration
|
||||
ai_provider = fields.Selection([
|
||||
|
||||
@@ -28,3 +28,4 @@ access_woo_category_map_manager,woo.category.map.manager,model_woo_category_map,
|
||||
access_woo_setup_wizard_manager,woo.setup.wizard.manager,model_woo_setup_wizard,fusion_woocommerce.group_woo_manager,1,1,1,1
|
||||
access_woo_product_fetch_manager,woo.product.fetch.manager,model_woo_product_fetch,fusion_woocommerce.group_woo_manager,1,1,1,1
|
||||
access_woo_product_create_wizard_manager,woo.product.create.wizard.manager,model_woo_product_create_wizard,fusion_woocommerce.group_woo_manager,1,1,1,1
|
||||
access_woo_category_filter_manager,woo.category.filter.manager,model_woo_category_filter,group_woo_manager,1,1,1,1
|
||||
|
||||
|
@@ -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>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from . import woo_setup_wizard
|
||||
from . import woo_product_fetch
|
||||
from . import woo_product_create
|
||||
from . import woo_category_filter
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class WooCategoryFilter(models.TransientModel):
|
||||
_name = 'woo.category.filter'
|
||||
_description = 'Manage Hidden Categories'
|
||||
|
||||
instance_id = fields.Many2one('woo.instance', required=True)
|
||||
category_ids = fields.Many2many(
|
||||
'product.category', string='Categories to Hide',
|
||||
help='Select categories you want to hide from the unmatched products list.',
|
||||
)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
instance_id = self.env.context.get('default_instance_id')
|
||||
if instance_id:
|
||||
instance = self.env['woo.instance'].browse(instance_id)
|
||||
res['category_ids'] = [(6, 0, instance.excluded_category_ids.ids)]
|
||||
return res
|
||||
|
||||
def action_save(self):
|
||||
"""Save the hidden categories to the instance."""
|
||||
self.ensure_one()
|
||||
self.instance_id.excluded_category_ids = [(6, 0, self.category_ids.ids)]
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def action_clear_all(self):
|
||||
"""Remove all hidden categories."""
|
||||
self.ensure_one()
|
||||
self.category_ids = [(5, 0, 0)]
|
||||
return self._reopen()
|
||||
|
||||
def _reopen(self):
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': self._name,
|
||||
'res_id': self.id,
|
||||
'views': [(False, 'form')],
|
||||
'target': 'new',
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="woo_category_filter_form_view" model="ir.ui.view">
|
||||
<field name="name">woo.category.filter.form</field>
|
||||
<field name="model">woo.category.filter</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Manage Hidden Categories">
|
||||
<sheet>
|
||||
<div class="alert alert-info" role="alert">
|
||||
Select the product categories you want to hide from the unmatched products list.
|
||||
These will persist across sessions. You can toggle them on/off from the product mapping screen.
|
||||
</div>
|
||||
<group>
|
||||
<field name="instance_id" invisible="1"/>
|
||||
<field name="category_ids" widget="many2many_tags"
|
||||
options="{'no_create': True}"
|
||||
placeholder="Search and select categories to hide..."/>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button name="action_save" type="object" string="Save" class="btn-primary"/>
|
||||
<button name="action_clear_all" type="object" string="Clear All" class="btn-secondary"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user