Explorar el Código

Fixes #9055: Restore ability to move inventory item to other device

jeremystretch hace 3 años
padre
commit
1e65ef0c1a

+ 1 - 0
docs/release-notes/version-3.2.md

@@ -9,6 +9,7 @@
 ### Bug Fixes
 
 * [#8931](https://github.com/netbox-community/netbox/issues/8931) - Copy assigned tenant when cloning a location
+* [#9055](https://github.com/netbox-community/netbox/issues/9055) - Restore ability to move inventory item to other device
 * [#9057](https://github.com/netbox-community/netbox/issues/9057) - Fix missing instance counts for module types
 * [#9061](https://github.com/netbox-community/netbox/issues/9061) - Change inheritance order for DeviceComponentFilterSets
 * [#9065](https://github.com/netbox-community/netbox/issues/9065) - Min/max VID should not be required when filtering VLAN groups

+ 5 - 1
netbox/dcim/forms/bulk_edit.py

@@ -1204,6 +1204,10 @@ class InventoryItemBulkEditForm(
     form_from_model(InventoryItem, ['label', 'role', 'manufacturer', 'part_id', 'description']),
     NetBoxModelBulkEditForm
 ):
+    device = DynamicModelChoiceField(
+        queryset=Device.objects.all(),
+        required=False
+    )
     role = DynamicModelChoiceField(
         queryset=InventoryItemRole.objects.all(),
         required=False
@@ -1215,7 +1219,7 @@ class InventoryItemBulkEditForm(
 
     model = InventoryItem
     fieldsets = (
-        (None, ('label', 'role', 'manufacturer', 'part_id', 'description')),
+        (None, ('device', 'label', 'role', 'manufacturer', 'part_id', 'description')),
     )
     nullable_fields = ('label', 'role', 'manufacturer', 'part_id', 'description')
 

+ 3 - 3
netbox/dcim/forms/models.py

@@ -1362,6 +1362,9 @@ class PopulateDeviceBayForm(BootstrapMixin, forms.Form):
 
 
 class InventoryItemForm(NetBoxModelForm):
+    device = DynamicModelChoiceField(
+        queryset=Device.objects.all()
+    )
     parent = DynamicModelChoiceField(
         queryset=InventoryItem.objects.all(),
         required=False,
@@ -1399,9 +1402,6 @@ class InventoryItemForm(NetBoxModelForm):
             'device', 'parent', 'name', 'label', 'role', 'manufacturer', 'part_id', 'serial', 'asset_tag',
             'description', 'component_type', 'component_id', 'tags',
         ]
-        widgets = {
-            'device': forms.HiddenInput(),
-        }
 
 
 #

+ 6 - 1
netbox/dcim/forms/object_create.py

@@ -1,7 +1,6 @@
 from django import forms
 
 from dcim.models import *
-from extras.models import Tag
 from netbox.forms import NetBoxModelForm
 from utilities.forms import (
     BootstrapMixin, DynamicModelChoiceField, DynamicModelMultipleChoiceField, ExpandableNameField,
@@ -12,6 +11,7 @@ __all__ = (
     'DeviceComponentCreateForm',
     'FrontPortCreateForm',
     'FrontPortTemplateCreateForm',
+    'InventoryItemCreateForm',
     'ModularComponentTemplateCreateForm',
     'ModuleBayCreateForm',
     'ModuleBayTemplateCreateForm',
@@ -199,6 +199,11 @@ class ModuleBayCreateForm(DeviceComponentCreateForm):
     field_order = ('device', 'name_pattern', 'label_pattern', 'position_pattern')
 
 
+class InventoryItemCreateForm(ComponentCreateForm):
+    # Device is assigned by the model form
+    field_order = ('name_pattern', 'label_pattern')
+
+
 class VirtualChassisCreateForm(NetBoxModelForm):
     region = DynamicModelChoiceField(
         queryset=Region.objects.all(),

+ 1 - 1
netbox/dcim/views.py

@@ -2517,7 +2517,7 @@ class InventoryItemEditView(generic.ObjectEditView):
 
 class InventoryItemCreateView(generic.ComponentCreateView):
     queryset = InventoryItem.objects.all()
-    form = forms.DeviceComponentCreateForm
+    form = forms.InventoryItemCreateForm
     model_form = forms.InventoryItemForm
     template_name = 'dcim/inventoryitem_create.html'