Better location validation messages

This commit is contained in:
Oliver Walters 2026-06-21 11:05:02 +00:00
parent a4dab942d0
commit d1c40ddb92
1 changed files with 30 additions and 3 deletions

View File

@ -1761,7 +1761,7 @@ class StockCountSerializer(StockAdjustmentSerializer):
fields = ['items', 'notes', 'location']
location = serializers.PrimaryKeyRelatedField(
queryset=StockLocation.objects.filter(structural=False),
queryset=StockLocation.objects.filter(),
many=False,
required=False,
allow_null=True,
@ -1769,6 +1769,15 @@ class StockCountSerializer(StockAdjustmentSerializer):
help_text=_('Set stock location for counted items (optional)'),
)
def validate_location(self, location):
"""Validate the provided location."""
if location and location.structural:
raise ValidationError(
_('Structural locations cannot be assigned stock items')
)
return location
def save(self):
"""Count stock."""
request = self.context['request']
@ -1865,7 +1874,7 @@ class StockTransferSerializer(StockAdjustmentSerializer):
items = StockAdjustmentItemSerializer(many=True, require_non_zero=True)
location = serializers.PrimaryKeyRelatedField(
queryset=StockLocation.objects.filter(structural=False),
queryset=StockLocation.objects.filter(),
many=False,
required=True,
allow_null=False,
@ -1873,6 +1882,15 @@ class StockTransferSerializer(StockAdjustmentSerializer):
help_text=_('Destination stock location'),
)
def validate_location(self, location):
"""Validate the provided location."""
if location and location.structural:
raise ValidationError(
_('Structural locations cannot be assigned stock items')
)
return location
def save(self):
"""Transfer stock."""
request = self.context['request']
@ -1914,7 +1932,7 @@ class StockReturnSerializer(StockAdjustmentSerializer):
)
location = serializers.PrimaryKeyRelatedField(
queryset=StockLocation.objects.filter(structural=False),
queryset=StockLocation.objects.filter(),
many=False,
required=True,
allow_null=False,
@ -1922,6 +1940,15 @@ class StockReturnSerializer(StockAdjustmentSerializer):
help_text=_('Destination stock location'),
)
def validate_location(self, location):
"""Validate the provided location."""
if location and location.structural:
raise ValidationError(
_('Structural locations cannot be assigned stock items')
)
return location
merge = serializers.BooleanField(
default=False,
required=False,