From 3063a3d14381c27cc4bde6c353a33d916c2992a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Tue, 10 Sep 2024 14:50:02 +0200 Subject: [PATCH] refund purchase from list --- games/templates/cotton/icon/refund.html | 8 ++++++++ games/urls.py | 5 +++++ games/views/purchase.py | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 games/templates/cotton/icon/refund.html diff --git a/games/templates/cotton/icon/refund.html b/games/templates/cotton/icon/refund.html new file mode 100644 index 0000000..4ff150c --- /dev/null +++ b/games/templates/cotton/icon/refund.html @@ -0,0 +1,8 @@ + + + + diff --git a/games/urls.py b/games/urls.py index fab22c6..99c0367 100644 --- a/games/urls.py +++ b/games/urls.py @@ -59,6 +59,11 @@ urlpatterns = [ purchase.list_purchases, name="list_purchases", ), + path( + "purchase//refund", + purchase.refund_purchase, + name="refund_purchase", + ), path( "purchase/related-purchase-by-edition", purchase.related_purchase_by_edition, diff --git a/games/views/purchase.py b/games/views/purchase.py index 7209d79..0d1e467 100644 --- a/games/views/purchase.py +++ b/games/views/purchase.py @@ -112,6 +112,15 @@ def list_purchases(request: HttpRequest) -> HttpResponse: } if not purchase.date_dropped else {}, + { + "href": reverse( + "refund_purchase", args=[purchase.pk] + ), + "slot": Icon("refund"), + "title": "Mark as refunded", + } + if not purchase.date_refunded + else {}, { "href": reverse( "edit_purchase", args=[purchase.pk] @@ -206,6 +215,14 @@ def drop_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: return redirect("list_sessions") +@login_required +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_sessions") + + def related_purchase_by_edition(request: HttpRequest) -> HttpResponse: edition_id = request.GET.get("edition") if not edition_id: