mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-08 16:11:23 +00:00
[UI] Tree select in form fields (#12217)
* Add TreeField component * Add chevrons in dropdown menu * Custom node rendering * Add childIdentifier * Ensure full value gets displayed * Fix for search results * Refactor old renderers * Override field types * use definition filters * Better location validation messages * Tweaks * Fix unit test * Include icon * Fix playwright test * Fix call to onValueChange * Updated playwright tests * Use pathstring in selectedLabel (if available) * Mark structural nodes * Retain selected value when dropdown open * Add better placeholder values * Simplify field selection
This commit is contained in:
@@ -1770,7 +1770,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,
|
||||
@@ -1778,6 +1778,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']
|
||||
@@ -1874,7 +1883,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,
|
||||
@@ -1882,6 +1891,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']
|
||||
@@ -1965,7 +1983,7 @@ class StockReturnSerializer(StockAdjustmentSerializer):
|
||||
)
|
||||
|
||||
location = serializers.PrimaryKeyRelatedField(
|
||||
queryset=StockLocation.objects.filter(structural=False),
|
||||
queryset=StockLocation.objects.filter(),
|
||||
many=False,
|
||||
required=True,
|
||||
allow_null=False,
|
||||
@@ -1973,6 +1991,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,
|
||||
|
||||
@@ -2435,7 +2435,10 @@ class StocktakeTest(StockAPITestCase):
|
||||
{'items': [{'pk': item_a.pk, 'quantity': 1}], 'location': structural.pk},
|
||||
expected_code=400,
|
||||
)
|
||||
self.assertIn('does not exist', str(response.data['location']))
|
||||
self.assertIn(
|
||||
'Structural locations cannot be assigned stock items',
|
||||
str(response.data['location']),
|
||||
)
|
||||
|
||||
|
||||
class StockTransferMergeTest(StockAPITestCase):
|
||||
|
||||
Reference in New Issue
Block a user