forked from data.coop/membersystem
Compare commits
3 commits
ca8987ba3b
...
3af6ae0097
Author | SHA1 | Date | |
---|---|---|---|
Benjamin Bach | 3af6ae0097 | ||
Benjamin Bach | a93a879f50 | ||
Benjamin Bach | 1070e93885 |
|
@ -43,7 +43,9 @@ class OrderAdmin(admin.ModelAdmin):
|
||||||
inlines = (OrderProductInline,)
|
inlines = (OrderProductInline,)
|
||||||
form = OrderAdminForm
|
form = OrderAdminForm
|
||||||
|
|
||||||
list_display = ("member", "description", "created", "is_paid")
|
list_display = ("member", "description", "created", "is_paid", "total_with_vat")
|
||||||
|
search_fields = ("member__email", "membership__membership_type__name", "description")
|
||||||
|
list_filter = ("is_paid", "membership__membership_type")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Payment)
|
@admin.register(models.Payment)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from hashlib import md5
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib import admin
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.aggregates import Sum
|
from django.db.models.aggregates import Sum
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
@ -96,6 +97,11 @@ class Order(CreatedModifiedAbstract):
|
||||||
return sum(item.vat * item.quantity for item in self.items.all())
|
return sum(item.vat * item.quantity for item in self.items.all())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@admin.display(
|
||||||
|
ordering=None,
|
||||||
|
description="Total (incl. VAT)",
|
||||||
|
boolean=False,
|
||||||
|
)
|
||||||
def total_with_vat(self) -> Money:
|
def total_with_vat(self) -> Money:
|
||||||
"""Return the TOTAL amount WITH VAT."""
|
"""Return the TOTAL amount WITH VAT."""
|
||||||
return self.total + self.total_vat
|
return self.total + self.total_vat
|
||||||
|
|
|
@ -102,7 +102,7 @@ def success(request: HttpRequest, order_id: int) -> HttpResponse:
|
||||||
quickly as possible.
|
quickly as possible.
|
||||||
"""
|
"""
|
||||||
user = request.user # People just need to login to pay something, not necessarily be a member
|
user = request.user # People just need to login to pay something, not necessarily be a member
|
||||||
order = models.Order.objects.get(pk=order_id, member=user)
|
order = get_object_or_404(models.Order, pk=order_id, member=user)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"order": order,
|
"order": order,
|
||||||
|
@ -168,7 +168,7 @@ def stripe_webhook(request: HttpRequest) -> HttpResponse:
|
||||||
if not models.Payment.objects.filter(order=order).exists():
|
if not models.Payment.objects.filter(order=order).exists():
|
||||||
models.Payment.objects.create(
|
models.Payment.objects.create(
|
||||||
order=order,
|
order=order,
|
||||||
amount=Money(event["data"]["object"]["amount_total"], event["data"]["object"]["currency"]),
|
amount=Money(event["data"]["object"]["amount_total"] / 100.0, event["data"]["object"]["currency"]),
|
||||||
description="Paid via Stripe",
|
description="Paid via Stripe",
|
||||||
payment_type=models.PaymentType.objects.get_or_create(name="Stripe")[0],
|
payment_type=models.PaymentType.objects.get_or_create(name="Stripe")[0],
|
||||||
external_transaction_id=event["id"],
|
external_transaction_id=event["id"],
|
||||||
|
|
|
@ -29,6 +29,10 @@ admin.site.unregister(User)
|
||||||
class MembershipAdmin(admin.ModelAdmin):
|
class MembershipAdmin(admin.ModelAdmin):
|
||||||
"""Admin for Membership model."""
|
"""Admin for Membership model."""
|
||||||
|
|
||||||
|
list_display = ("user", "period", "membership_type", "activated", "revoked")
|
||||||
|
list_filter = ("period", "membership_type", "activated", "revoked")
|
||||||
|
search_fields = ("membership_type__name", "user__email", "user__first_name", "user__last_name")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(MembershipType)
|
@admin.register(MembershipType)
|
||||||
class MembershipTypeAdmin(admin.ModelAdmin):
|
class MembershipTypeAdmin(admin.ModelAdmin):
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 5.1b1 on 2024-08-04 10:26
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('membership', '0007_membership_activated_membership_activated_on_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='membership',
|
||||||
|
name='membership_type',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='memberships', to='membership.membershiptype', verbose_name='membership type'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -125,7 +125,7 @@ class Membership(CreatedModifiedAbstract):
|
||||||
membership_type = models.ForeignKey(
|
membership_type = models.ForeignKey(
|
||||||
"membership.MembershipType",
|
"membership.MembershipType",
|
||||||
related_name="memberships",
|
related_name="memberships",
|
||||||
verbose_name=_("subscription type"),
|
verbose_name=_("membership type"),
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue