diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 3e874e91e5..36ea8d453d 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -121,12 +121,17 @@ class StockAdjust(APIView): - StockAdd: add stock items - StockRemove: remove stock items - StockTransfer: transfer stock items + + # TODO - This needs serious refactoring!!! + """ permission_classes = [ permissions.IsAuthenticated, ] + allow_missing_quantity = False + def get_items(self, request): """ Return a list of items posted to the endpoint. @@ -157,11 +162,13 @@ class StockAdjust(APIView): except (ValueError, StockItem.DoesNotExist): raise ValidationError({'pk': 'Each entry must contain a valid pk field'}) + if self.allow_missing_quantity and 'quantity' not in entry: + entry['quantity'] = item.quantity + try: quantity = Decimal(str(entry.get('quantity', None))) except (ValueError, TypeError, InvalidOperation): - # Default to the quantity of the item - quantity = item.quantity + raise ValidationError({'quantity': "Each entry must contain a valid quantity value"}) if quantity < 0: raise ValidationError({'quantity': 'Quantity field must not be less than zero'}) @@ -235,6 +242,8 @@ class StockTransfer(StockAdjust): API endpoint for performing stock movements """ + allow_missing_quantity = True + def post(self, request, *args, **kwargs): self.get_items(request)