API cleanup

Add / Remove / Count endpoints now work
This commit is contained in:
Oliver Walters 2020-04-10 00:03:43 +10:00
parent 3e5dc65c49
commit 41b3f1d39c
2 changed files with 14 additions and 20 deletions

View File

@ -163,27 +163,12 @@ class StockCount(StockAdjust):
self.get_items(request) self.get_items(request)
"""
if 'notes' in request.data:
notes = request.data['notes']
n = 0 n = 0
for item in items: for item in self.items:
quantity = int(item['quantity'])
if action == u'count': if item['item'].stocktake(item['quantity'], request.user, notes=self.notes):
if item['item'].stocktake(quantity, request.user, notes=notes): n += 1
n += 1
elif action == u'remove':
if item['item'].take_stock(quantity, request.user, notes=notes):
n += 1
elif action == u'add':
if item['item'].add_stock(quantity, request.user, notes=notes):
n += 1
"""
n = 0
return Response({'success': 'Updated stock for {n} items'.format(n=n)}) return Response({'success': 'Updated stock for {n} items'.format(n=n)})
@ -199,6 +184,10 @@ class StockAdd(StockAdjust):
n = 0 n = 0
for item in self.items:
if item['item'].add_stock(item['quantity'], request.user, notes=self.notes):
n += 1
return Response({"success": "Added stock for {n} items".format(n=n)}) return Response({"success": "Added stock for {n} items".format(n=n)})
@ -213,7 +202,12 @@ class StockRemove(StockAdjust):
n = 0 n = 0
return Response({"success": "Added stock for {n} items".format(n=n)}) for item in self.items:
if item['item'].take_stock(item['quantity'], request.user, notes=self.notes):
n += 1
return Response({"success": "Removed stock for {n} items".format(n=n)})
class StockTransfer(APIView): class StockTransfer(APIView):

View File

@ -85,7 +85,7 @@ class StocktakeTest(APITestCase):
self.client.login(username='testuser', password='password') self.client.login(username='testuser', password='password')
def doPost(self, url, data={}): def doPost(self, url, data={}):
response = self.client.post(url, data=data, format='json') response = self.client.post(url, data=data, format='json')
return response return response