From b73583be40d466e1b629d9c16f8b783913365129 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 11 May 2019 09:02:30 +1000 Subject: [PATCH] Make the 'quantity' field optional in the stock move API If not specified, the entire quantity will be moved --- InvenTree/stock/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 0bd048087e..9f305b657a 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -178,7 +178,11 @@ class StockMove(APIView): for item in stock_list: try: stock_id = int(item['pk']) - quantity = int(item['quantity']) + if 'quantity' in item: + quantity = int(item['quantity']) + else: + # If quantity not supplied, we'll move the entire stock + quantity = None except ValueError: # Ignore this one continue @@ -192,6 +196,9 @@ class StockMove(APIView): except StockItem.DoesNotExist: continue + if quantity is None: + quantity = stock.quantity + stock.move(location, data.get('notes'), request.user, quantity=quantity) return Response({'success': 'Moved parts to {loc}'.format(