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_setup_wizard_views.xml',
|
||||||
'wizard/woo_product_fetch_views.xml',
|
'wizard/woo_product_fetch_views.xml',
|
||||||
'wizard/woo_product_create_views.xml',
|
'wizard/woo_product_create_views.xml',
|
||||||
|
'wizard/woo_category_filter_views.xml',
|
||||||
],
|
],
|
||||||
'assets': {
|
'assets': {
|
||||||
'web.assets_backend': [
|
'web.assets_backend': [
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ class WooProductSearchController(http.Controller):
|
|||||||
type='jsonrpc', auth='user', methods=['POST'],
|
type='jsonrpc', auth='user', methods=['POST'],
|
||||||
)
|
)
|
||||||
def search_odoo_products(self, query='', instance_id=None, limit=20, offset=0,
|
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).
|
Search Odoo products by name or internal reference (SKU).
|
||||||
|
|
||||||
@@ -61,6 +62,12 @@ class WooProductSearchController(http.Controller):
|
|||||||
if exclude_category_ids:
|
if exclude_category_ids:
|
||||||
domain.append(('categ_id', 'not in', [int(x) for x in 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)
|
total = request.env['product.product'].search_count(domain)
|
||||||
products = request.env['product.product'].search(domain, limit=limit, offset=offset)
|
products = request.env['product.product'].search(domain, limit=limit, offset=offset)
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ class WooInstance(models.Model):
|
|||||||
|
|
||||||
# Category mapping
|
# Category mapping
|
||||||
category_map_ids = fields.One2many('woo.category.map', 'instance_id', string='Category Mappings')
|
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 Configuration
|
||||||
ai_provider = fields.Selection([
|
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_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_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_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,
|
pageSize: 50,
|
||||||
|
|
||||||
// Category filters
|
// Category filters
|
||||||
odooCategories: [],
|
categoryFilterActive: true,
|
||||||
odooFilterCategoryId: false,
|
excludedCategoryCount: 0,
|
||||||
odooExcludeCategoryIds: [],
|
|
||||||
|
|
||||||
// Conflicts tab
|
// Conflicts tab
|
||||||
conflicts: [],
|
conflicts: [],
|
||||||
@@ -71,7 +70,7 @@ export class ProductMapping extends Component {
|
|||||||
|
|
||||||
onWillStart(async () => {
|
onWillStart(async () => {
|
||||||
await this._loadInstances();
|
await this._loadInstances();
|
||||||
await this._loadOdooCategories();
|
await this._loadExcludedCategoryCount();
|
||||||
await this._refreshAll();
|
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 {
|
try {
|
||||||
const result = await rpc("/woo/search/odoo_categories", {});
|
const result = await rpc("/web/dataset/call_kw", {
|
||||||
this.state.odooCategories = result || [];
|
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) {
|
} 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) {
|
if (this.state.instanceId) {
|
||||||
params.instance_id = this.state.instanceId;
|
params.instance_id = this.state.instanceId;
|
||||||
}
|
}
|
||||||
if (this.state.odooFilterCategoryId) {
|
// Pass excluded categories if filter is active
|
||||||
params.category_id = this.state.odooFilterCategoryId;
|
if (this.state.categoryFilterActive && this.state.instanceId) {
|
||||||
}
|
params.apply_excluded = true;
|
||||||
if (this.state.odooExcludeCategoryIds.length) {
|
|
||||||
params.exclude_category_ids = JSON.stringify(this.state.odooExcludeCategoryIds);
|
|
||||||
}
|
}
|
||||||
const result = await rpc("/woo/search/odoo_products", params);
|
const result = await rpc("/woo/search/odoo_products", params);
|
||||||
this.state.odooProducts = (result && result.results) || [];
|
this.state.odooProducts = (result && result.results) || [];
|
||||||
@@ -285,34 +293,28 @@ export class ProductMapping extends Component {
|
|||||||
// Category filter
|
// Category filter
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
async onOdooCategoryFilter(ev) {
|
async openCategoryFilter() {
|
||||||
const val = ev.target.value;
|
if (!this.state.instanceId) {
|
||||||
this.state.odooFilterCategoryId = val ? parseInt(val, 10) : false;
|
this.notification.add("Select an instance first.", { type: "warning" });
|
||||||
this.state.unmatchedOdooPage = 1;
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
await this.actionService.doAction({
|
||||||
|
type: 'ir.actions.act_window',
|
||||||
async applyExcludeCategories() {
|
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;
|
this.state.unmatchedOdooPage = 1;
|
||||||
await this._loadOdooProducts("");
|
await this._loadOdooProducts("");
|
||||||
}
|
}
|
||||||
|
|
||||||
isCategoryExcluded(catId) {
|
async toggleCategoryFilter() {
|
||||||
return this.state.odooExcludeCategoryIds.includes(catId);
|
this.state.categoryFilterActive = !this.state.categoryFilterActive;
|
||||||
}
|
|
||||||
|
|
||||||
async clearCategoryFilter() {
|
|
||||||
this.state.odooFilterCategoryId = false;
|
|
||||||
this.state.odooExcludeCategoryIds = [];
|
|
||||||
this.state.unmatchedOdooPage = 1;
|
this.state.unmatchedOdooPage = 1;
|
||||||
await this._loadOdooProducts("");
|
await this._loadOdooProducts("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,18 +336,20 @@
|
|||||||
<div class="woo-split-panel-header" style="flex-wrap: wrap; gap: 6px;">
|
<div class="woo-split-panel-header" style="flex-wrap: wrap; gap: 6px;">
|
||||||
<span>Odoo Products</span>
|
<span>Odoo Products</span>
|
||||||
<div class="d-flex gap-2 align-items-center">
|
<div class="d-flex gap-2 align-items-center">
|
||||||
<select class="woo-filter-select" t-on-change="onOdooCategoryFilter">
|
<button class="woo-btn woo-btn-secondary woo-btn-sm"
|
||||||
<option value="">All Categories</option>
|
t-on-click="openCategoryFilter"
|
||||||
<t t-foreach="state.odooCategories" t-as="cat" t-key="cat.id">
|
title="Manage hidden categories">
|
||||||
<option t-att-value="cat.id"
|
<i class="fa fa-filter me-1"/>
|
||||||
t-att-selected="state.odooFilterCategoryId === cat.id">
|
Hidden
|
||||||
<t t-esc="cat.complete_name"/>
|
<t t-if="state.excludedCategoryCount">
|
||||||
</option>
|
(<t t-esc="state.excludedCategoryCount"/>)
|
||||||
</t>
|
</t>
|
||||||
</select>
|
</button>
|
||||||
<t t-if="state.odooFilterCategoryId || state.odooExcludeCategoryIds.length">
|
<t t-if="state.excludedCategoryCount">
|
||||||
<button class="woo-btn-icon" title="Clear filter" t-on-click="clearCategoryFilter">
|
<button t-att-class="'woo-btn woo-btn-sm ' + (state.categoryFilterActive ? 'woo-btn-primary' : 'woo-btn-secondary')"
|
||||||
<i class="fa fa-times"/>
|
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>
|
</button>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
from . import woo_setup_wizard
|
from . import woo_setup_wizard
|
||||||
from . import woo_product_fetch
|
from . import woo_product_fetch
|
||||||
from . import woo_product_create
|
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