From b41dbba2b0205239b7c2e6d7bf2193615f4f2cd3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 4 Nov 2021 23:18:59 +1100 Subject: [PATCH] Correctly handle serialization of newly created stock --- InvenTree/stock/api.py | 21 ++++++++++++++++++++- InvenTree/templates/js/translated/forms.js | 6 ++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 5ca552dd8e..9d2860e41d 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -445,8 +445,14 @@ class StockList(generics.ListCreateAPIView): # Finally, save the item (with user information) item.save(user=user) - # Serialize the stock, if required if serials: + """ + Serialize the stock, if required + + - Note that the "original" stock item needs to be created first, so it can be serialized + - It is then immediately deleted + """ + try: item.serializeStock( quantity, @@ -455,6 +461,19 @@ class StockList(generics.ListCreateAPIView): notes=notes, location=item.location, ) + + headers = self.get_success_headers(serializer.data) + + # Delete the original item + item.delete() + + response_data = { + 'quantity': quantity, + 'serial_numbers': serials, + } + + return Response(response_data, status=status.HTTP_201_CREATED, headers=headers) + except DjangoValidationError as e: raise ValidationError({ 'quantity': e.messages, diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index 0da32c58ff..42e3aac289 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -115,6 +115,10 @@ function canDelete(OPTIONS) { */ function getApiEndpointOptions(url, callback) { + if (!url) { + return; + } + // Return the ajax request object $.ajax({ url: url, @@ -727,6 +731,8 @@ function submitFormData(fields, options) { break; default: $(options.modal).modal('hide'); + + console.log(`upload error at ${options.url}`); showApiError(xhr, options.url); break; }