phase 1 partial

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-13 22:12:25 +00:00
parent 0b24fe8c77
commit 60263b4682
5 changed files with 2012 additions and 192 deletions

View File

@@ -1,5 +1,8 @@
"""
Billing Business Logic Admin
NOTE: Most billing models are registered in modules/billing/admin.py
with full workflow functionality. This file contains legacy/minimal registrations.
"""
from django.contrib import admin
from django.utils.html import format_html
@@ -14,133 +17,36 @@ from .models import (
)
@admin.register(CreditCostConfig)
class CreditCostConfigAdmin(admin.ModelAdmin):
list_display = [
'operation_type',
'display_name',
'credits_cost_display',
'unit',
'is_active',
'cost_change_indicator',
'updated_at',
'updated_by'
]
list_filter = ['is_active', 'unit', 'updated_at']
search_fields = ['operation_type', 'display_name', 'description']
fieldsets = (
('Operation', {
'fields': ('operation_type', 'display_name', 'description')
}),
('Cost Configuration', {
'fields': ('credits_cost', 'unit', 'is_active')
}),
('Audit Trail', {
'fields': ('previous_cost', 'updated_by', 'created_at', 'updated_at'),
'classes': ('collapse',)
}),
)
readonly_fields = ['created_at', 'updated_at', 'previous_cost']
def credits_cost_display(self, obj):
"""Show cost with color coding"""
if obj.credits_cost >= 20:
color = 'red'
elif obj.credits_cost >= 10:
color = 'orange'
else:
color = 'green'
return format_html(
'<span style="color: {}; font-weight: bold;">{} credits</span>',
color,
obj.credits_cost
)
credits_cost_display.short_description = 'Cost'
def cost_change_indicator(self, obj):
"""Show if cost changed recently"""
if obj.previous_cost is not None:
if obj.credits_cost > obj.previous_cost:
icon = '📈' # Increased
color = 'red'
elif obj.credits_cost < obj.previous_cost:
icon = '📉' # Decreased
color = 'green'
else:
icon = '➡️' # Same
color = 'gray'
return format_html(
'{} <span style="color: {};">({}{})</span>',
icon,
color,
obj.previous_cost,
obj.credits_cost
)
return ''
cost_change_indicator.short_description = 'Recent Change'
def save_model(self, request, obj, form, change):
"""Track who made the change"""
obj.updated_by = request.user
super().save_model(request, obj, form, change)
# CreditCostConfig - DUPLICATE - Registered in modules/billing/admin.py with better features
# Commenting out to avoid conflicts
# @admin.register(CreditCostConfig)
# class CreditCostConfigAdmin(admin.ModelAdmin):
# ...existing implementation...
@admin.register(Invoice)
class InvoiceAdmin(AccountAdminMixin, admin.ModelAdmin):
list_display = [
'invoice_number',
'account',
'status',
'total',
'currency',
'invoice_date',
'due_date',
'subscription',
]
list_filter = ['status', 'currency', 'invoice_date', 'account']
search_fields = ['invoice_number', 'account__name', 'subscription__id']
readonly_fields = ['created_at', 'updated_at']
# Invoice - DUPLICATE - Registered in modules/billing/admin.py
# Commenting out to avoid conflicts
# @admin.register(Invoice)
# class InvoiceAdmin(AccountAdminMixin, admin.ModelAdmin):
# ...existing implementation...
@admin.register(Payment)
class PaymentAdmin(AccountAdminMixin, admin.ModelAdmin):
\"\"\"
Payment admin - DO NOT USE.
Use the Payment admin in modules/billing/admin.py which has approval workflow actions.
This is kept for backward compatibility only.
\"\"\"
list_display = [
'id',
'invoice',
'account',
'payment_method',
'status',
'amount',
'currency',
'processed_at',
]
list_filter = ['status', 'payment_method', 'currency', 'created_at']
search_fields = ['invoice__invoice_number', 'account__name', 'stripe_payment_intent_id', 'paypal_order_id']
readonly_fields = ['created_at', 'updated_at']
def has_add_permission(self, request):\n return False # Prevent creating payments here
\n def has_delete_permission(self, request, obj=None):\n return False # Prevent deleting payments here
# Payment - DUPLICATE - Registered in modules/billing/admin.py with full approval workflow
# Commenting out to avoid conflicts
# @admin.register(Payment)
# class PaymentAdmin(AccountAdminMixin, admin.ModelAdmin):
# ...existing implementation...
@admin.register(CreditPackage)
class CreditPackageAdmin(admin.ModelAdmin):
list_display = ['name', 'slug', 'credits', 'price', 'discount_percentage', 'is_active', 'is_featured', 'sort_order']
list_filter = ['is_active', 'is_featured']
search_fields = ['name', 'slug']
readonly_fields = ['created_at', 'updated_at']
# CreditPackage - DUPLICATE - Registered in modules/billing/admin.py
# Commenting out to avoid conflicts
# @admin.register(CreditPackage)
# class CreditPackageAdmin(admin.ModelAdmin):
# ...existing implementation...
# PaymentMethodConfig admin is in modules/billing/admin.py - do not duplicate
# @admin.register(PaymentMethodConfig)
# PaymentMethodConfig and AccountPaymentMethod are kept here as they're not duplicated
# or have minimal implementations that don't conflict
@admin.register(AccountPaymentMethod)
class AccountPaymentMethodAdmin(admin.ModelAdmin):