fixes fixes fixes tenaancy
This commit is contained in:
@@ -68,6 +68,14 @@ class InvoiceAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||
|
||||
@admin.register(Payment)
|
||||
class PaymentAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||
"""
|
||||
Main Payment Admin with approval workflow.
|
||||
When you change status to 'succeeded', it automatically:
|
||||
- Updates invoice to 'paid'
|
||||
- Activates subscription
|
||||
- Activates account
|
||||
- Adds credits
|
||||
"""
|
||||
list_display = [
|
||||
'id',
|
||||
'invoice',
|
||||
@@ -93,6 +101,37 @@ class PaymentAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||
readonly_fields = ['created_at', 'updated_at', 'approved_at', 'processed_at', 'failed_at', 'refunded_at']
|
||||
actions = ['approve_payments', 'reject_payments']
|
||||
|
||||
fieldsets = (
|
||||
('Payment Info', {
|
||||
'fields': ('invoice', 'account', 'amount', 'currency', 'payment_method', 'status')
|
||||
}),
|
||||
('Manual Payment Details', {
|
||||
'fields': ('manual_reference', 'manual_notes', 'admin_notes'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('Stripe/PayPal', {
|
||||
'fields': ('stripe_payment_intent_id', 'stripe_charge_id', 'paypal_order_id', 'paypal_capture_id'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('Approval Info', {
|
||||
'fields': ('approved_by', 'approved_at', 'processed_at', 'failed_at', 'refunded_at', 'failure_reason'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('Timestamps', {
|
||||
'fields': ('created_at', 'updated_at'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
"""
|
||||
Override save_model to set approved_by when status changes to succeeded.
|
||||
The Payment.save() method will handle all the cascade updates automatically.
|
||||
"""
|
||||
if obj.status == 'succeeded' and not obj.approved_by:
|
||||
obj.approved_by = request.user
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
def approve_payments(self, request, queryset):
|
||||
"""Approve selected manual payments"""
|
||||
from django.db import transaction
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated by GitHub Copilot on 2025-12-09 02:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('billing', '0006_accountpaymentmethod'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='payment',
|
||||
name='status',
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
('pending_approval', 'Pending Approval'),
|
||||
('succeeded', 'Succeeded'),
|
||||
('failed', 'Failed'),
|
||||
('refunded', 'Refunded')
|
||||
],
|
||||
db_index=True,
|
||||
default='pending_approval',
|
||||
max_length=20
|
||||
),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user