Fixes for unit tests

This commit is contained in:
Oliver Walters 2021-01-28 22:37:28 +11:00
parent c61631a380
commit e8d73c78eb

View File

@ -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)