mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Fix data mutability issues
This commit is contained in:
parent
d0aa09337a
commit
4a45ba3a44
@ -5,6 +5,7 @@ JSON API for the Stock app
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||||
@ -463,6 +464,11 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
user = request.user
|
user = request.user
|
||||||
|
|
||||||
|
# Copy the request data, to side-step "mutability" issues
|
||||||
|
data = OrderedDict()
|
||||||
|
data.update(request.data)
|
||||||
|
|
||||||
data = request.data
|
data = request.data
|
||||||
|
|
||||||
quantity = data.get('quantity', None)
|
quantity = data.get('quantity', None)
|
||||||
@ -476,7 +482,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
part = Part.objects.get(pk=data.get('part', None))
|
part = Part.objects.get(pk=data.get('part', None))
|
||||||
except (ValueError, Part.DoesNotExist):
|
except (ValueError, Part.DoesNotExist):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'part': _('Valid part ID must be supplied'),
|
'part': _('Valid part must be supplied'),
|
||||||
})
|
})
|
||||||
|
|
||||||
# Set default location (if not provided)
|
# Set default location (if not provided)
|
||||||
|
@ -342,7 +342,7 @@ class StockItemTest(StockAPITestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertContains(response, 'This field is required', status_code=status.HTTP_400_BAD_REQUEST)
|
self.assertContains(response, 'Valid part must be supplied', status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# POST with an invalid part reference
|
# POST with an invalid part reference
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ class StockItemTest(StockAPITestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertContains(response, 'does not exist', status_code=status.HTTP_400_BAD_REQUEST)
|
self.assertContains(response, 'Valid part must be supplied', status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# POST without quantity
|
# POST without quantity
|
||||||
response = self.post(
|
response = self.post(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user