From bc1092b0b3347516218a1a3f4cd6052f1aeaf511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Tue, 17 Feb 2026 22:14:36 +0100 Subject: [PATCH] Add prompt to set game to Abandoned upon refund --- CHANGELOG.md | 5 +++ .../refund_purchase_confirmation.html | 23 +++++++++++++ games/urls.py | 5 +++ games/views/purchase.py | 34 ++++++++++++++++--- 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 games/templates/partials/refund_purchase_confirmation.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e5d9de..dfaa79d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +### Improved +* Add a prompt to set game to Abandoned upon refund + ## 1.6.1 / 2026-01-30 11:48+01:00 ### New diff --git a/games/templates/partials/refund_purchase_confirmation.html b/games/templates/partials/refund_purchase_confirmation.html new file mode 100644 index 0000000..e1c2785 --- /dev/null +++ b/games/templates/partials/refund_purchase_confirmation.html @@ -0,0 +1,23 @@ +
+
+
+

Confirm Refund

+

+ Are you sure you want to mark this purchase as refunded? +

+
+ {% csrf_token %} +
+ +
+
+ Refund + Cancel +
+
+
+
+
diff --git a/games/urls.py b/games/urls.py index 0ccf0ae..92594e1 100644 --- a/games/urls.py +++ b/games/urls.py @@ -88,6 +88,11 @@ urlpatterns = [ purchase.list_purchases, name="list_purchases", ), + path( + "purchase//refund/confirm", + purchase.refund_purchase_confirmation, + name="refund_purchase_confirmation", + ), path( "purchase//refund", purchase.refund_purchase, diff --git a/games/views/purchase.py b/games/views/purchase.py index d00615b..c3d91e0 100644 --- a/games/views/purchase.py +++ b/games/views/purchase.py @@ -72,9 +72,12 @@ def list_purchases(request: HttpRequest) -> HttpResponse: { "buttons": [ { - "href": reverse( - "refund_purchase", args=[purchase.pk] + "href": "#", + "hx_get": reverse( + "refund_purchase_confirmation", + args=[purchase.pk], ), + "hx_target": "#global-modal-container", "slot": Icon("refund"), "title": "Mark as refunded", } @@ -186,11 +189,32 @@ def drop_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: @login_required +def refund_purchase_confirmation( + request: HttpRequest, purchase_id: int +) -> HttpResponse: + # purchase = get_object_or_404(Purchase, id=purchase_id) + return render( + request, + "partials/refund_purchase_confirmation.html", + {"purchase_id": purchase_id}, + ) + + +@login_required +@require_POST def refund_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: purchase = get_object_or_404(Purchase, id=purchase_id) - purchase.date_refunded = timezone.now() - purchase.save() - return redirect("list_purchases") + + if request.POST.get("set_abandoned"): + for game in purchase.games.all(): + game.status = Game.Status.ABANDONED + game.save() + + purchase.refund() + + response = HttpResponse(status=204) + response["HX-Redirect"] = reverse("list_purchases") + return response @login_required