mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
12255 inventory item device change (#12311)
* #12255 allow inventory items to change devices * #12255 allow inventory item template to change devices * #12255 fix init * 12255 remove can_swtich from template model * 12255 change to check module list
This commit is contained in:
parent
12bb0ec1fe
commit
38a0ed5e24
@ -81,11 +81,25 @@ class ComponentTemplateModel(WebhooksMixin, ChangeLoggedModel):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Cache the original DeviceType ID for reference under clean()
|
||||||
|
self._original_device_type = self.device_type_id
|
||||||
|
|
||||||
def to_objectchange(self, action):
|
def to_objectchange(self, action):
|
||||||
objectchange = super().to_objectchange(action)
|
objectchange = super().to_objectchange(action)
|
||||||
objectchange.related_object = self.device_type
|
objectchange.related_object = self.device_type
|
||||||
return objectchange
|
return objectchange
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
if self.pk is not None and self._original_device_type != self.device_type_id:
|
||||||
|
raise ValidationError({
|
||||||
|
"device_type": "Component templates cannot be moved to a different device type."
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class ModularComponentTemplateModel(ComponentTemplateModel):
|
class ModularComponentTemplateModel(ComponentTemplateModel):
|
||||||
"""
|
"""
|
||||||
@ -120,12 +134,6 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
# Cache the original DeviceType ID for reference under clean()
|
|
||||||
self._original_device_type = self.device_type_id
|
|
||||||
|
|
||||||
def to_objectchange(self, action):
|
def to_objectchange(self, action):
|
||||||
objectchange = super().to_objectchange(action)
|
objectchange = super().to_objectchange(action)
|
||||||
if self.device_type is not None:
|
if self.device_type is not None:
|
||||||
@ -137,11 +145,6 @@ class ModularComponentTemplateModel(ComponentTemplateModel):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.pk is not None and self._original_device_type != self.device_type_id:
|
|
||||||
raise ValidationError({
|
|
||||||
"device_type": "Component templates cannot be moved to a different device type."
|
|
||||||
})
|
|
||||||
|
|
||||||
# A component template must belong to a DeviceType *or* to a ModuleType
|
# A component template must belong to a DeviceType *or* to a ModuleType
|
||||||
if self.device_type and self.module_type:
|
if self.device_type and self.module_type:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
|
@ -97,7 +97,8 @@ class ComponentModel(NetBoxModel):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.pk is not None and self._original_device != self.device_id:
|
# Check list of Modules that allow device field to be changed
|
||||||
|
if (type(self) not in [InventoryItem]) and (self.pk is not None) and (self._original_device != self.device_id):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"device": "Components cannot be moved to a different device."
|
"device": "Components cannot be moved to a different device."
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user