feat: tenant-aware netbox-inventory assets

Assets without a tenant take the tenant of the device, module, inventory item or
rack they are assigned to, both in clean() and before save. The plugin's assign,
reassign and "create hardware from asset" views save assets without a tenant
field and failed with mandatory tenancy before. Asset forms are also pre-filled
from an assigned module or inventory item. Existing tenants are never changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-18 12:43:08 +01:00
1 parent 4dd01b82e3
commit cf1cafb632
5 files changed
+134 -1

No files matched your search

+4 -1
View File
@@ -7,7 +7,7 @@ from django.forms.models import BaseModelForm
from tenancy.models import Tenant
from .runtime import tenant_required
from .tenant_autofill import apply_cable_instance_tenant, apply_tenant_autofill
from .tenant_autofill import apply_asset_instance_tenant, apply_cable_instance_tenant, apply_tenant_autofill
VALIDATION_MESSAGE = "Für dieses Objekt muss ein Mandant angegeben werden."
@@ -37,6 +37,7 @@ def _install_model_clean_validation(model):
@wraps(original_clean)
def tenant_aware_clean(instance, *args, **kwargs):
apply_cable_instance_tenant(instance)
apply_asset_instance_tenant(instance)
result = original_clean(instance, *args, **kwargs)
validate_tenant_assignment(instance)
return result
@@ -65,6 +66,8 @@ def _install_form_validation():
def _enforce_before_save(sender, instance, raw=False, **kwargs):
if not raw:
# netbox-inventory saves assets in several views without calling clean()
apply_asset_instance_tenant(instance)
validate_tenant_assignment(instance)