RosterChief charging the clubs, which is a different domain from `shop` (a club charging its members). Nothing here is club-scoped: these rows reference a Club, they are not owned by one, and no club user ever sees them. - Tier + TierPrice. Prices are dated, not keyed by year: a rate change is one row with a future active_from, and price_on(day) answers "what was in force then". A tier with no price yet returns None, which callers must treat as "cannot bill" -- never as free. - Due: one rolling-year period per club, with a 45-day grace tail. The tier and the amount are SNAPSHOTS taken when the period opens. Raise the price and last year's period must still say what was actually charged; reading it back through the tier would silently rewrite financial history. - DuePayment: partial payments accumulate. amount_paid is re-summed from the payments on every change, never incremented -- an increment drifts the moment a payment is deleted, and the drift still looks like money. - Invoice: PDF via WeasyPrint, rendered on demand from the frozen snapshot. Only the number is stored, in one platform-wide series (unlike the shop's per-club order numbers), and re-issuing returns the existing one rather than burning a number -- a gap in an invoice series is a question you don't want to answer. WeasyPrint is imported lazily: it binds to native pango/cairo, and the app, the tests and every other page must still run on a machine without them. - archive_overdue_clubs reports by default and archives only with --commit. That asymmetry is deliberate: this switches off paying customers, so a bad clock or a cron misconfiguration should cost an email, not a morning of angry clubs. A club with auto_archive off is spared entirely. Renewal continues from the last period end, not from the payment date: a club that pays two months late has still used those two months. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from django.contrib import admin
|
|
|
|
from .models import Due, DuePayment, Subscription, Tier, TierPrice
|
|
|
|
|
|
class TierPriceInline(admin.TabularInline):
|
|
model = TierPrice
|
|
extra = 0
|
|
|
|
|
|
@admin.register(Tier)
|
|
class TierAdmin(admin.ModelAdmin):
|
|
list_display = ["name", "is_active"]
|
|
list_filter = ["is_active"]
|
|
search_fields = ["name"]
|
|
prepopulated_fields = {"slug": ["name"]}
|
|
inlines = [TierPriceInline]
|
|
|
|
|
|
@admin.register(TierPrice)
|
|
class TierPriceAdmin(admin.ModelAdmin):
|
|
list_display = ["tier", "amount", "active_from"]
|
|
list_filter = ["tier"]
|
|
|
|
|
|
@admin.register(Subscription)
|
|
class SubscriptionAdmin(admin.ModelAdmin):
|
|
list_display = ["club", "tier", "auto_archive"]
|
|
list_filter = ["tier", "auto_archive"]
|
|
search_fields = ["club__name"]
|
|
|
|
|
|
class DuePaymentInline(admin.TabularInline):
|
|
model = DuePayment
|
|
extra = 0
|
|
readonly_fields = ["recorded_by"]
|
|
|
|
|
|
@admin.register(Due)
|
|
class DueAdmin(admin.ModelAdmin):
|
|
list_display = ["club", "tier", "period_start", "period_end", "amount", "amount_paid", "status"]
|
|
list_filter = ["status", "tier"]
|
|
search_fields = ["club__name"]
|
|
# Money is settled by the billing service, which re-derives these from the payments.
|
|
readonly_fields = ["amount_paid", "status", "paid_at"]
|
|
inlines = [DuePaymentInline]
|
|
|
|
|
|
@admin.register(DuePayment)
|
|
class DuePaymentAdmin(admin.ModelAdmin):
|
|
list_display = ["due", "amount", "method", "paid_at", "recorded_by"]
|
|
list_filter = ["method"]
|
|
search_fields = ["due__club__name", "reference"]
|