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:
@@ -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