From 6512c0061eed3f4356faaeff81fb27ec497806e2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 17 May 2022 00:35:24 +1000 Subject: [PATCH] Catch a 500 and make it a 400 While we are at it, convert __all__ to non_field_errors automatically --- InvenTree/InvenTree/exceptions.py | 5 +++++ InvenTree/order/serializers.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/exceptions.py b/InvenTree/InvenTree/exceptions.py index f57df8ac00..78a494c9f2 100644 --- a/InvenTree/InvenTree/exceptions.py +++ b/InvenTree/InvenTree/exceptions.py @@ -77,4 +77,9 @@ def exception_handler(exc, context): # For an error response, include status code information response.data['status_code'] = response.status_code + # Convert errors returned under the label '__all__' to 'non_field_errors' + if '__all__' in response.data: + response.data['non_field_errors'] = response.data['all'] + del response.data['__all__'] + return response diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index c97090e4f6..1c261e7a86 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -1287,13 +1287,17 @@ class SalesOrderShipmentAllocationSerializer(serializers.Serializer): with transaction.atomic(): for entry in items: + # Create a new SalesOrderAllocation - order.models.SalesOrderAllocation.objects.create( + allocation = order.models.SalesOrderAllocation( line=entry.get('line_item'), item=entry.get('stock_item'), quantity=entry.get('quantity'), shipment=shipment, ) + + allocation.full_clean() + allocation.save() class SalesOrderExtraLineSerializer(AbstractExtraLineSerializer, InvenTreeModelSerializer):