diff --git a/netbox_inventory/forms/reassign.py b/netbox_inventory/forms/reassign.py index 494432e..2258d84 100644 --- a/netbox_inventory/forms/reassign.py +++ b/netbox_inventory/forms/reassign.py @@ -1,9 +1,11 @@ from django import forms from django.core.exceptions import ValidationError +from django.utils.translation import gettext_lazy as _ from dcim.models import Device, InventoryItem, Module, Site, Location, Manufacturer from netbox.forms import NetBoxModelForm from utilities.forms.fields import DynamicModelChoiceField +from utilities.forms.rendering import FieldSet from ..choices import AssetStatusChoices from ..models import Asset, InventoryItemType, InventoryItemGroup from ..utils import get_status_for @@ -31,10 +33,16 @@ class AssetReassignMixin(forms.Form): asset_status = forms.ChoiceField( choices=AssetStatusChoices, initial=get_status_for('stored'), - label='Old Asset Status', + label='Status', help_text='Status to set to existing asset that is being unassigned', ) + fieldsets = ( + FieldSet('storage_site', 'storage_location', 'assigned_asset', + name=_('New Asset')), + FieldSet('asset_status', name=_('Old Asset')), + ) + class Meta: fields = ('storage_site', 'storage_location', 'assigned_asset', 'asset_status') @@ -113,7 +121,8 @@ def __init__(self, *args, **kwargs): self.instance.assigned_asset except Asset.DoesNotExist: # no asset currently assigned, hide status field for old asset - self.fields['asset_status'].widget = forms.HiddenInput() + self.fields.pop('asset_status') + self.fieldsets = (self.fieldsets[0],) class AssetDeviceReassignForm(AssetReassignMixin, NetBoxModelForm): @@ -215,6 +224,13 @@ class AssetInventoryItemReassignForm(AssetReassignMixin, NetBoxModelForm): help_text='New asset to assign to inventory item. Set to blank to remove assignment.', ) + fieldsets = ( + FieldSet('manufacturer', 'inventoryitem_group', 'inventoryitem_type', + 'storage_site', 'storage_location', 'assigned_asset', + name=_('New Asset')), + FieldSet('asset_status', name=_('Old Asset')), + ) + class Meta: model = InventoryItem fields = ('manufacturer', 'inventoryitem_group', 'inventoryitem_type') + AssetReassignMixin.Meta.fields