prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Delete tpay payment if order is modified
  ### Summary
  Right now it is possible to order a pizza, pay it with tpay, change the order to a pizza with a different price, and the payment will not match the order anymore.
  
  ### How to test
  1. Order a pizza
  2. Pay with tpay
  3. Change the order
  4. The payment should be deleted
  5. If the event is over, or the payment is batched, then changing the order should crash
  
  </issue>
  <code>
  [start of website/pizzas/views.py]
  1 """Views provided by the pizzas package."""
  2 from django.contrib import messages
  3 from django.contrib.auth.decorators import login_required
  4 from django.http import Http404
  5 from django.shortcuts import get_object_or_404, render, redirect
  6 from django.utils.translation import gettext_lazy as _
  7 from django.views.decorators.http import require_http_methods
  8 
  9 from payments.services import delete_payment
  10 from .models import FoodOrder, FoodEvent, Product
  11 
  12 
  13 @login_required
  14 def index(request):
  15     """Overview of user order for a pizza event."""
  16     products = Product.available_products.order_by("name")
  17     if not request.user.has_perm("pizzas.order_restricted_products"):
  18         products = products.exclude(restricted=True)
  19     event = FoodEvent.current()
  20     try:
  21         obj = FoodOrder.objects.get(food_event=event, member=request.member)
  22     except FoodOrder.DoesNotExist:
  23         obj = None
  24     context = {"event": event, "products": products, "order": obj}
  25     return render(request, "pizzas/index.html", context)
  26 
  27 
  28 @require_http_methods(["POST"])
  29 def cancel_order(request):
  30     """View that cancels a user's order."""
  31     if "order" in request.POST:
  32         try:
  33             order = get_object_or_404(FoodOrder, pk=int(request.POST["order"]))
  34             if not order.can_be_changed:
  35                 messages.error(request, _("You can no longer cancel."))
  36             elif order.member == request.member:
  37                 order.delete()
  38                 messages.success(request, _("Your order has been cancelled."))
  39         except Http404:
  40             messages.error(request, _("Your order could not be found."))
  41     return redirect("pizzas:index")
  42 
  43 
  44 @login_required
  45 def place_order(request):
  46     """View that shows the detail of the current order."""
  47     event = FoodEvent.current()
  48     if not event:
  49         return redirect("pizzas:index")
  50 
  51     try:
  52         obj = FoodOrder.objects.get(food_event=event, member=request.member)
  53         current_order_locked = not obj.can_be_changed
  54     except FoodOrder.DoesNotExist:
  55         obj = None
  56         current_order_locked = False
  57 
  58     if "product" in request.POST and not current_order_locked:
  59         productset = Product.available_products.all()
  60         if not request.user.has_perm("pizzas.order_restricted_products"):
  61             productset = productset.exclude(restricted=True)
  62         try:
  63             product = productset.get(pk=int(request.POST["product"]))
  64         except Product.DoesNotExist as e:
  65             raise Http404("Pizza does not exist") from e
  66         if not obj:
  67             obj = FoodOrder(food_event=event, member=request.member)
  68         obj.product = product
  69         if obj.payment:
  70             delete_payment(obj.payment)
  71         obj.save()
  72     return redirect("pizzas:index")
  73
  [end of website/pizzas/views.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/website/pizzas/views.py b/website/pizzas/views.py
  --- a/website/pizzas/views.py
  +++ b/website/pizzas/views.py
  @@ -67,6 +67,6 @@
               obj = FoodOrder(food_event=event, member=request.member)
           obj.product = product
           if obj.payment:
  -            delete_payment(obj.payment)
  +            delete_payment(obj)
           obj.save()
       return redirect("pizzas:index")
  
verification_info: {"golden_diff": "diff --git a/website/pizzas/views.py b/website/pizzas/views.py\n--- a/website/pizzas/views.py\n+++ b/website/pizzas/views.py\n@@ -67,6 +67,6 @@\n             obj = FoodOrder(food_event=event, member=request.member)\n         obj.product = product\n         if obj.payment:\n-            delete_payment(obj.payment)\n+            delete_payment(obj)\n         obj.save()\n     return redirect(\"pizzas:index\")\n", "issue": "Delete tpay payment if order is modified\n### Summary\r\nRight now it is possible to order a pizza, pay it with tpay, change the order to a pizza with a different price, and the payment will not match the order anymore.\r\n\r\n### How to test\r\n1. Order a pizza\r\n2. Pay with tpay\r\n3. Change the order\r\n4. The payment should be deleted\r\n5. If the event is over, or the payment is batched, then changing the order should crash\n", "before_files": [{"content": "\"\"\"Views provided by the pizzas package.\"\"\"\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.http import Http404\nfrom django.shortcuts import get_object_or_404, render, redirect\nfrom django.utils.translation import gettext_lazy as _\nfrom django.views.decorators.http import require_http_methods\n\nfrom payments.services import delete_payment\nfrom .models import FoodOrder, FoodEvent, Product\n\n\n@login_required\ndef index(request):\n    \"\"\"Overview of user order for a pizza event.\"\"\"\n    products = Product.available_products.order_by(\"name\")\n    if not request.user.has_perm(\"pizzas.order_restricted_products\"):\n        products = products.exclude(restricted=True)\n    event = FoodEvent.current()\n    try:\n        obj = FoodOrder.objects.get(food_event=event, member=request.member)\n    except FoodOrder.DoesNotExist:\n        obj = None\n    context = {\"event\": event, \"products\": products, \"order\": obj}\n    return render(request, \"pizzas/index.html\", context)\n\n\n@require_http_methods([\"POST\"])\ndef cancel_order(request):\n    \"\"\"View that cancels a user's order.\"\"\"\n    if \"order\" in request.POST:\n        try:\n            order = get_object_or_404(FoodOrder, pk=int(request.POST[\"order\"]))\n            if not order.can_be_changed:\n                messages.error(request, _(\"You can no longer cancel.\"))\n            elif order.member == request.member:\n                order.delete()\n                messages.success(request, _(\"Your order has been cancelled.\"))\n        except Http404:\n            messages.error(request, _(\"Your order could not be found.\"))\n    return redirect(\"pizzas:index\")\n\n\n@login_required\ndef place_order(request):\n    \"\"\"View that shows the detail of the current order.\"\"\"\n    event = FoodEvent.current()\n    if not event:\n        return redirect(\"pizzas:index\")\n\n    try:\n        obj = FoodOrder.objects.get(food_event=event, member=request.member)\n        current_order_locked = not obj.can_be_changed\n    except FoodOrder.DoesNotExist:\n        obj = None\n        current_order_locked = False\n\n    if \"product\" in request.POST and not current_order_locked:\n        productset = Product.available_products.all()\n        if not request.user.has_perm(\"pizzas.order_restricted_products\"):\n            productset = productset.exclude(restricted=True)\n        try:\n            product = productset.get(pk=int(request.POST[\"product\"]))\n        except Product.DoesNotExist as e:\n            raise Http404(\"Pizza does not exist\") from e\n        if not obj:\n            obj = FoodOrder(food_event=event, member=request.member)\n        obj.product = product\n        if obj.payment:\n            delete_payment(obj.payment)\n        obj.save()\n    return redirect(\"pizzas:index\")\n", "path": "website/pizzas/views.py"}]}