Answers "does a plan renew itself?": until now, no — and that was a silent revenue leak, not merely a missing convenience. A club whose period ended with its last due PAID owes nothing, so dues_overdue() is empty, so archive_overdue_clubs never fires. The club kept using the platform for free and no dashboard number went red, because nothing was ever billed. The safety net only caught clubs you remembered to invoice. `renew_subscriptions` (cron) issues the next period 30 days before the current one ends, so the invoice lands before the period lapses and grace only matters for genuine non-payers. It is idempotent by construction: a just-renewed club has a latest period a year out, past the horizon, so a second run is a no-op. It ACTS by default and previews with --dry-run — the opposite asymmetry to archiving, and deliberately so. Archiving switches off a customer, so not-acting is safe there; here, not-acting is the expensive failure, because an unbilled club is also an unchased one. An unpriced tier fails that one club loudly (non-zero exit, so cron mails you) without stopping the rest. Opt-out per club via Subscription.auto_renew, mirroring auto_archive: off means you invoice that club by hand. The dashboard gains a "renewals pending" count that should sit at ~0 — a number here means cron has died and a club is about to go free, which no other metric would reveal. 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_renew", "auto_archive"]
|
|
list_filter = ["tier", "auto_renew", "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"]
|