From 2ec41b02f82336a121110611e277e2a0dd82f4b5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 29 Dec 2021 03:01:52 +0100 Subject: [PATCH] append information about next serial numbe to fnc call Fixes #2484 --- InvenTree/build/views.py | 4 ++-- InvenTree/order/serializers.py | 2 +- InvenTree/stock/api.py | 25 +++++++++++++------------ InvenTree/stock/serializers.py | 3 ++- InvenTree/stock/views.py | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index fd730b6a7e..1d28cb8d50 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -109,7 +109,7 @@ class BuildOutputCreate(AjaxUpdateView): # Check that the serial numbers are valid if serials: try: - extracted = extract_serial_numbers(serials, quantity) + extracted = extract_serial_numbers(serials, quantity, build.part.getLatestSerialNumberInt()) if extracted: # Check for conflicting serial numbers @@ -143,7 +143,7 @@ class BuildOutputCreate(AjaxUpdateView): serials = data.get('serial_numbers', None) if serials: - serial_numbers = extract_serial_numbers(serials, quantity) + serial_numbers = extract_serial_numbers(serials, quantity, build.part.getLatestSerialNumberInt()) else: serial_numbers = None diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index 32e50943b1..6097a707c7 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -861,7 +861,7 @@ class SOSerialAllocationSerializer(serializers.Serializer): part = line_item.part try: - data['serials'] = extract_serial_numbers(serial_numbers, quantity) + data['serials'] = extract_serial_numbers(serial_numbers, quantity, part.getLatestSerialNumberInt()) except DjangoValidationError as e: raise ValidationError({ 'serial_numbers': e.messages, diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index d69c94b4a8..fa15708b6d 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -466,18 +466,6 @@ class StockList(generics.ListCreateAPIView): notes = data.get('notes', '') - serials = None - - if serial_numbers: - # If serial numbers are specified, check that they match! - try: - serials = extract_serial_numbers(serial_numbers, quantity) - except DjangoValidationError as e: - raise ValidationError({ - 'quantity': e.messages, - 'serial_numbers': e.messages, - }) - with transaction.atomic(): # Create an initial stock item @@ -493,6 +481,19 @@ class StockList(generics.ListCreateAPIView): if item.part.default_expiry > 0: item.expiry_date = datetime.now().date() + timedelta(days=item.part.default_expiry) + # fetch serial numbers + serials = None + + if serial_numbers: + # If serial numbers are specified, check that they match! + try: + serials = extract_serial_numbers(serial_numbers, quantity, item.part.getLatestSerialNumberInt()) + except DjangoValidationError as e: + raise ValidationError({ + 'quantity': e.messages, + 'serial_numbers': e.messages, + }) + # Finally, save the item (with user information) item.save(user=user) diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index e69cd90f82..5379273a2e 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -350,7 +350,7 @@ class SerializeStockItemSerializer(serializers.Serializer): serial_numbers = data['serial_numbers'] try: - serials = InvenTree.helpers.extract_serial_numbers(serial_numbers, quantity) + serials = InvenTree.helpers.extract_serial_numbers(serial_numbers, quantity, item.part.getLatestSerialNumberInt()) except DjangoValidationError as e: raise ValidationError({ 'serial_numbers': e.messages, @@ -379,6 +379,7 @@ class SerializeStockItemSerializer(serializers.Serializer): serials = InvenTree.helpers.extract_serial_numbers( data['serial_numbers'], data['quantity'], + item.part.getLatestSerialNumberInt() ) item.serializeStock( diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 27801f0ed6..6c89db0f2f 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -1241,7 +1241,7 @@ class StockItemCreate(AjaxCreateView): if len(sn) > 0: try: - serials = extract_serial_numbers(sn, quantity) + serials = extract_serial_numbers(sn, quantity, part.getLatestSerialNumberInt()) except ValidationError as e: serials = None form.add_error('serial_numbers', e.messages) @@ -1283,7 +1283,7 @@ class StockItemCreate(AjaxCreateView): # Create a single stock item for each provided serial number if len(sn) > 0: - serials = extract_serial_numbers(sn, quantity) + serials = extract_serial_numbers(sn, quantity, part.getLatestSerialNumberInt()) for serial in serials: item = StockItem(