Commit 5fb3d4f4 authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Fix crash when pizza event admin orders pizza

parent 7255f425
......@@ -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"]
else:
payment_type = Payment.NONE
instance = super().create(validated_data)
instance.payment.type = payment_type
instance.payment.save()
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