Repository: netbox-community/netbox

Issue:
Add fields to components filter
### NetBox version

v3.2.0

### Feature type

Change to existing functionality

### Proposed functionality

Currently we have the following component filters:

![image](https://user-images.githubusercontent.com/91552302/162026716-c52dc82c-6484-4a79-8d40-dd00f449f331.png)

I have noticed that I can't easily filter device types and module types when I want to know if they have device bays or module bays configured. I've been using tags to keep track of this, but I think this should be on the filters tab, so I would propose the addition of the following filter choices:

- Has Device Bays
- Has Module Bays
- Has Inventory Items

### Use case

To be able to filter for components that currently are not possible.

### Database changes

None.

### External dependencies

_No response_


Discussion:

Resolving patch:
diff --git a/netbox/dcim/filtersets.py b/netbox/dcim/filtersets.py
--- a/netbox/dcim/filtersets.py
+++ b/netbox/dcim/filtersets.py
@@ -435,6 +435,10 @@ class DeviceTypeFilterSet(NetBoxModelFilterSet):
         method='_device_bays',
         label='Has device bays',
     )
+    inventory_items = django_filters.BooleanFilter(
+        method='_inventory_items',
+        label='Has inventory items',
+    )
 
     class Meta:
         model = DeviceType
@@ -479,6 +483,9 @@ def _module_bays(self, queryset, name, value):
     def _device_bays(self, queryset, name, value):
         return queryset.exclude(devicebaytemplates__isnull=value)
 
+    def _inventory_items(self, queryset, name, value):
+        return queryset.exclude(inventoryitemtemplates__isnull=value)
+
 
 class ModuleTypeFilterSet(NetBoxModelFilterSet):
     manufacturer_id = django_filters.ModelMultipleChoiceFilter(
diff --git a/netbox/dcim/forms/filtersets.py b/netbox/dcim/forms/filtersets.py
--- a/netbox/dcim/forms/filtersets.py
+++ b/netbox/dcim/forms/filtersets.py
@@ -331,7 +331,7 @@ class DeviceTypeFilterForm(NetBoxModelFilterSetForm):
         ('Hardware', ('manufacturer_id', 'part_number', 'subdevice_role', 'airflow')),
         ('Components', (
             'console_ports', 'console_server_ports', 'power_ports', 'power_outlets', 'interfaces',
-            'pass_through_ports',
+            'pass_through_ports', 'device_bays', 'module_bays', 'inventory_items',
         )),
     )
     manufacturer_id = DynamicModelMultipleChoiceField(
@@ -392,6 +392,27 @@ class DeviceTypeFilterForm(NetBoxModelFilterSetForm):
             choices=BOOLEAN_WITH_BLANK_CHOICES
         )
     )
+    device_bays = forms.NullBooleanField(
+        required=False,
+        label='Has device bays',
+        widget=StaticSelect(
+            choices=BOOLEAN_WITH_BLANK_CHOICES
+        )
+    )
+    module_bays = forms.NullBooleanField(
+        required=False,
+        label='Has module bays',
+        widget=StaticSelect(
+            choices=BOOLEAN_WITH_BLANK_CHOICES
+        )
+    )
+    inventory_items = forms.NullBooleanField(
+        required=False,
+        label='Has inventory items',
+        widget=StaticSelect(
+            choices=BOOLEAN_WITH_BLANK_CHOICES
+        )
+    )
     tag = TagFilterField(model)
 
 


Test patch: