diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 9961bb7bae..a016f9057f 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -180,6 +180,20 @@ class StockAssign(generics.CreateAPIView): return ctx +class StockMerge(generics.CreateAPIView): + """ + API endpoint for merging multiple stock items + """ + + queryset = StockItem.objects.none() + serializer_class = StockSerializers.StockMergeSerializer + + def get_serializer_context(self): + ctx = super().get_serializer_context() + ctx['request'] = self.request + return ctx + + class StockLocationList(generics.ListCreateAPIView): """ API endpoint for list view of StockLocation objects: @@ -1213,6 +1227,7 @@ stock_api_urls = [ url(r'^remove/', StockRemove.as_view(), name='api-stock-remove'), url(r'^transfer/', StockTransfer.as_view(), name='api-stock-transfer'), url(r'^assign/', StockAssign.as_view(), name='api-stock-assign'), + url(r'^merge/', StockMerge.as_view(), name='api-stock-merge'), # StockItemAttachment API endpoints url(r'^attachment/', include([ diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index e69cd90f82..551d660f7b 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -674,6 +674,39 @@ class StockAssignmentSerializer(serializers.Serializer): ) +class StockMergeSerializer(serializers.Serializer): + """ + Serializer for merging two (or more) stock items together + """ + + class Meta: + fields = [ + # 'items', + 'location', + ] + + location = serializers.PrimaryKeyRelatedField( + queryset=StockLocation.objects.all(), + many=False, + required=True, + allow_null=False, + label=_('Location'), + help_text=_('Destination stock location'), + ) + + def validate(self, data): + + data = super().validate(data) + + # TODO: Custom data validation + + return data + + def save(self): + # TODO + pass + + class StockAdjustmentItemSerializer(serializers.Serializer): """ Serializer for a single StockItem within a stock adjument request. @@ -837,7 +870,7 @@ class StockTransferSerializer(StockAdjustmentSerializer): def validate(self, data): - super().validate(data) + data = super().validate(data) # TODO: Any specific validation of location field?