mirror of
https://github.com/inventree/InvenTree.git
synced 2026-08-21 20:45:13 +00:00
feat(frontend): Add filter navigation remove button (#12668)
* feat(frontend): Add filter navigation remove button * extend docs * extract and extend labels * add spacer * fix test * small fix * remove unneeded labels * add mechanism for not triggering on viewsets * reduce diff for now * fix test --------- Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
@@ -98,22 +98,25 @@ class TagsFilter(rest_filters.CharFilter):
|
||||
"""Filter which accepts a comma-separated list of tag names and returns only objects that have ALL of the specified tags.
|
||||
|
||||
Example usage in a FilterSet:
|
||||
tags = TagsFilter(label=_('Tags'))
|
||||
tags = TagsFilter()
|
||||
|
||||
Example query:
|
||||
?tags=apple,banana → returns only items tagged with both 'apple' AND 'banana'
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
_is_viewset: bool = False
|
||||
|
||||
def __init__(self, is_viewset: bool = False, *args, **kwargs):
|
||||
"""Initialize the filter."""
|
||||
if 'label' not in kwargs:
|
||||
kwargs['label'] = _('Tags')
|
||||
|
||||
self._is_viewset = is_viewset
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def filter(self, qs, value):
|
||||
"""Filter queryset to items matching all provided tag names."""
|
||||
if not value:
|
||||
if not value or (self._is_viewset and InvenTree.helpers.is_bool(value)):
|
||||
return qs
|
||||
|
||||
tag_names = [t.strip() for t in value.split(',') if t.strip()]
|
||||
|
||||
@@ -152,7 +152,7 @@ class ManufacturerPartFilter(FilterSet):
|
||||
field_name='manufacturer__active', label=_('Manufacturer is Active')
|
||||
)
|
||||
|
||||
tags = common.filters.TagsFilter(label=_('Tags'))
|
||||
tags = common.filters.TagsFilter()
|
||||
|
||||
|
||||
class ManufacturerOutputOptions(OutputConfiguration):
|
||||
@@ -308,7 +308,7 @@ class SupplierPartFilter(FilterSet):
|
||||
else:
|
||||
return queryset.exclude(in_stock__gt=0)
|
||||
|
||||
tags = common.filters.TagsFilter(label=_('Tags'))
|
||||
tags = common.filters.TagsFilter()
|
||||
|
||||
|
||||
class SupplierPartOutputOptions(OutputConfiguration):
|
||||
|
||||
@@ -374,6 +374,8 @@ class PurchaseOrderFilter(OrderFilter):
|
||||
"""
|
||||
return queryset.filter(lines__build_order=build).distinct()
|
||||
|
||||
tags = common.filters.TagsFilter(is_viewset=True)
|
||||
|
||||
|
||||
class PurchaseOrderOutputOptions(OutputConfiguration):
|
||||
"""Output options for the PurchaseOrder endpoint."""
|
||||
|
||||
@@ -171,6 +171,9 @@ class PurchaseOrderTest(OrderTest):
|
||||
self.filter({'supplier_part': 3}, 2)
|
||||
self.filter({'supplier_part': 4}, 0)
|
||||
|
||||
# Filter by "tags"
|
||||
self.filter({'tags': True}, 7)
|
||||
|
||||
def test_total_price(self):
|
||||
"""Unit tests for the 'total_price' field."""
|
||||
# Ensure we have exchange rate data
|
||||
|
||||
@@ -412,7 +412,7 @@ class StockLocationFilter(FilterSet):
|
||||
|
||||
return queryset
|
||||
|
||||
tags = common.filters.TagsFilter(label=_('Tags'))
|
||||
tags = common.filters.TagsFilter()
|
||||
|
||||
|
||||
class StockLocationMixin(SerializerContextMixin):
|
||||
@@ -1067,7 +1067,7 @@ class StockFilter(FilterSet):
|
||||
children = loc_obj.getUniqueChildren()
|
||||
return queryset.filter(location__in=children)
|
||||
|
||||
tags = common.filters.TagsFilter(label=_('Tags'))
|
||||
tags = common.filters.TagsFilter()
|
||||
|
||||
|
||||
class StockApiMixin(SerializerContextMixin):
|
||||
|
||||
Reference in New Issue
Block a user