Add prompt to set game to Abandoned upon refund
Django CI/CD / test (push) Successful in 36s
Django CI/CD / build-and-push (push) Successful in 1m55s

This commit is contained in:
2026-02-17 22:14:36 +01:00
parent 996c0107c9
commit bc1092b0b3
4 changed files with 62 additions and 5 deletions
+5
View File
@@ -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 ## 1.6.1 / 2026-01-30 11:48+01:00
### New ### New
@@ -0,0 +1,23 @@
<div id="refund-confirmation-modal" class="fixed inset-0 bg-black/70 dark:bg-gray-600/50 overflow-y-auto h-full w-full flex items-center justify-center">
<div class="relative mx-auto p-5 border-accent border w-full max-w-md shadow-lg/50 rounded-md bg-white dark:bg-gray-900">
<div class="">
<h1 class="text-2xl leading-6 font-medium dark:text-white text-center">Confirm Refund</h3>
<p class="dark:text-white text-center mt-5">
Are you sure you want to mark this purchase as refunded?
</p>
<form class="" hx-post="{% url 'refund_purchase' purchase_id %}" hx-target="#modal-container" hx-swap="innerHTML">
{% csrf_token %}
<div class="mt-5 text-center">
<label class="flex flex-row items-center justify-center align-baseline gap-5">
<input type="checkbox" name="set_abandoned" class="form-checkbox h-5 w-5 text-blue-600">
<span class="text-gray-700 dark:text-gray-500 underline decoration-dotted" title="Set the status of all games associated with this purchase to 'Abandoned'">Set status to 'Abandoned'</span>
</label>
</div>
<div class="items-center mt-5">
<c-button color="blue" size="lg" type="submit" class="w-full">Refund</c-button>
<c-button color="gray" size="base" class="mt-0 w-full" onclick="this.closest('#refund-confirmation-modal').remove()">Cancel</c-button>
</div>
</form>
</div>
</div>
</div>
+5
View File
@@ -88,6 +88,11 @@ urlpatterns = [
purchase.list_purchases, purchase.list_purchases,
name="list_purchases", name="list_purchases",
), ),
path(
"purchase/<int:purchase_id>/refund/confirm",
purchase.refund_purchase_confirmation,
name="refund_purchase_confirmation",
),
path( path(
"purchase/<int:purchase_id>/refund", "purchase/<int:purchase_id>/refund",
purchase.refund_purchase, purchase.refund_purchase,
+29 -5
View File
@@ -72,9 +72,12 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
{ {
"buttons": [ "buttons": [
{ {
"href": reverse( "href": "#",
"refund_purchase", args=[purchase.pk] "hx_get": reverse(
"refund_purchase_confirmation",
args=[purchase.pk],
), ),
"hx_target": "#global-modal-container",
"slot": Icon("refund"), "slot": Icon("refund"),
"title": "Mark as refunded", "title": "Mark as refunded",
} }
@@ -186,11 +189,32 @@ def drop_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
@login_required @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: def refund_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse:
purchase = get_object_or_404(Purchase, id=purchase_id) purchase = get_object_or_404(Purchase, id=purchase_id)
purchase.date_refunded = timezone.now()
purchase.save() if request.POST.get("set_abandoned"):
return redirect("list_purchases") 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 @login_required