Add prompt to set game to Abandoned upon refund
This commit is contained in:
@@ -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>
|
||||
@@ -88,6 +88,11 @@ urlpatterns = [
|
||||
purchase.list_purchases,
|
||||
name="list_purchases",
|
||||
),
|
||||
path(
|
||||
"purchase/<int:purchase_id>/refund/confirm",
|
||||
purchase.refund_purchase_confirmation,
|
||||
name="refund_purchase_confirmation",
|
||||
),
|
||||
path(
|
||||
"purchase/<int:purchase_id>/refund",
|
||||
purchase.refund_purchase,
|
||||
|
||||
+29
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user