mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Merge remote-tracking branch 'inventree/master'
This commit is contained in:
@ -186,7 +186,7 @@ class StockCount(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):
|
||||
@ -204,7 +204,7 @@ class StockAdd(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):
|
||||
|
@ -99,26 +99,10 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
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)
|
||||
|
||||
supplier_part = serializers.PrimaryKeyRelatedField(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)
|
||||
|
||||
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
||||
|
@ -73,6 +73,7 @@ $("#add-test-result").click(function() {
|
||||
stock_item: {{ item.id }},
|
||||
},
|
||||
success: reloadTable,
|
||||
focus: 'test',
|
||||
}
|
||||
);
|
||||
});
|
||||
@ -89,6 +90,7 @@ $("#test-result-table").on('click', '.button-test-add', function() {
|
||||
test: test_name
|
||||
},
|
||||
success: reloadTable,
|
||||
focus: 'value',
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -81,6 +81,59 @@ class StockItemTest(StockAPITestCase):
|
||||
response = self.client.get(self.list_url, format='json')
|
||||
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):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user