mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Merge pull request #944 from SchrodingersGat/stock-item-api-fix
Stock item api fix
This commit is contained in:
commit
35cd3923a5
@ -186,7 +186,7 @@ class StockCount(StockAdjust):
|
|||||||
|
|
||||||
class StockAdd(StockAdjust):
|
class StockAdd(StockAdjust):
|
||||||
"""
|
"""
|
||||||
Endpoint for adding stock
|
Endpoint for adding a quantity of stock to an existing StockItem
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
@ -204,7 +204,7 @@ class StockAdd(StockAdjust):
|
|||||||
|
|
||||||
class StockRemove(StockAdjust):
|
class StockRemove(StockAdjust):
|
||||||
"""
|
"""
|
||||||
Endpoint for removing stock.
|
Endpoint for removing a quantity of stock from an existing StockItem.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
@ -99,26 +99,10 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
belongs_to = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
build_order = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
customer = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
location = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
in_stock = serializers.BooleanField(read_only=True)
|
|
||||||
|
|
||||||
sales_order = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
supplier_part = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
supplier_part_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
|
supplier_part_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
|
||||||
|
|
||||||
part = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
||||||
|
|
||||||
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||||
|
|
||||||
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
||||||
|
@ -81,6 +81,59 @@ class StockItemTest(StockAPITestCase):
|
|||||||
response = self.client.get(self.list_url, format='json')
|
response = self.client.get(self.list_url, format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_stock_item_create(self):
|
||||||
|
"""
|
||||||
|
Test creation of a StockItem via the API
|
||||||
|
"""
|
||||||
|
|
||||||
|
# POST with an empty part reference
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
self.list_url,
|
||||||
|
data={
|
||||||
|
'quantity': 10,
|
||||||
|
'location': 1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertContains(response, 'This field is required', status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# POST with an invalid part reference
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
self.list_url,
|
||||||
|
data={
|
||||||
|
'quantity': 10,
|
||||||
|
'location': 1,
|
||||||
|
'part': 10000000,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertContains(response, 'does not exist', status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# POST without quantity
|
||||||
|
response = self.client.post(
|
||||||
|
self.list_url,
|
||||||
|
data={
|
||||||
|
'part': 1,
|
||||||
|
'location': 1,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertContains(response, 'This field is required', status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# POST with quantity and part and location
|
||||||
|
response = self.client.post(
|
||||||
|
self.list_url,
|
||||||
|
data={
|
||||||
|
'part': 1,
|
||||||
|
'location': 1,
|
||||||
|
'quantity': 10,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
|
||||||
class StocktakeTest(StockAPITestCase):
|
class StocktakeTest(StockAPITestCase):
|
||||||
"""
|
"""
|
||||||
|
@ -24,4 +24,5 @@ django-stdimage==5.1.1 # Advanced ImageField management
|
|||||||
django-tex==1.1.7 # LaTeX PDF export
|
django-tex==1.1.7 # LaTeX PDF export
|
||||||
django-weasyprint==1.0.1 # HTML PDF export
|
django-weasyprint==1.0.1 # HTML PDF export
|
||||||
django-debug-toolbar==2.2 # Debug / profiling toolbar
|
django-debug-toolbar==2.2 # Debug / profiling toolbar
|
||||||
|
|
||||||
inventree # Install the latest version of the InvenTree API python library
|
inventree # Install the latest version of the InvenTree API python library
|
Loading…
x
Reference in New Issue
Block a user