Commit 52177352 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'fix/pizza-order-crash' into 'master'

Fix crash when pizza event admin orders pizza

See merge request !1519
parents 86c59599 5fb3d4f4
......@@ -46,7 +46,9 @@ class AdminOrderSerializer(serializers.ModelSerializer):
model = Order
fields = ("pk", "payment", "product", "name", "member", "display_name")
payment = PaymentTypeField(source="payment.type", choices=Payment.PAYMENT_TYPE)
payment = PaymentTypeField(
source="payment.type", choices=Payment.PAYMENT_TYPE, required=False
display_name = serializers.SerializerMethodField("_display_name")
def _display_name(self, instance):
......@@ -66,6 +68,18 @@ class AdminOrderSerializer(serializers.ModelSerializer):
attrs["member"] = self.context["request"].member
return super().validate(attrs)
def create(self, validated_data: Any) -> Any:
if "payment" in validated_data:
payment_type = validated_data["payment"].get("type", Payment.NONE)
del validated_data["payment"]
payment_type = Payment.NONE
instance = super().create(validated_data)
instance.payment.type = payment_type
return instance
def update(self, instance: Model, validated_data: Any) -> Any:
if (
validated_data.get("payment", {}).get("type", instance.payment.type)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment