django admin improvement complete
This commit is contained in:
@@ -5,6 +5,7 @@ from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from django.contrib import messages
|
||||
from unfold.admin import ModelAdmin
|
||||
from simple_history.admin import SimpleHistoryAdmin
|
||||
from igny8_core.admin.base import AccountAdminMixin, Igny8ModelAdmin
|
||||
from igny8_core.business.billing.models import (
|
||||
CreditCostConfig,
|
||||
@@ -93,7 +94,7 @@ class PaymentResource(resources.ModelResource):
|
||||
|
||||
|
||||
@admin.register(Payment)
|
||||
class PaymentAdmin(ExportMixin, AccountAdminMixin, Igny8ModelAdmin):
|
||||
class PaymentAdmin(ExportMixin, AccountAdminMixin, SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
"""
|
||||
Main Payment Admin with approval workflow.
|
||||
When you change status to 'succeeded', it automatically:
|
||||
@@ -421,7 +422,7 @@ class AccountPaymentMethodAdmin(AccountAdminMixin, Igny8ModelAdmin):
|
||||
|
||||
|
||||
@admin.register(CreditCostConfig)
|
||||
class CreditCostConfigAdmin(Igny8ModelAdmin):
|
||||
class CreditCostConfigAdmin(SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
list_display = [
|
||||
'operation_type',
|
||||
'display_name',
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-15 01:28
|
||||
|
||||
import django.core.validators
|
||||
import django.db.models.deletion
|
||||
import simple_history.models
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('billing', '0016_remove_payment_payment_account_status_created_idx_and_more'),
|
||||
('igny8_core_auth', '0017_add_history_tracking'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='HistoricalCreditCostConfig',
|
||||
fields=[
|
||||
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
|
||||
('operation_type', models.CharField(choices=[('clustering', 'Keyword Clustering'), ('idea_generation', 'Content Ideas Generation'), ('content_generation', 'Content Generation'), ('image_generation', 'Image Generation'), ('reparse', 'Content Reparse'), ('ideas', 'Content Ideas Generation'), ('content', 'Content Generation'), ('images', 'Image Generation')], db_index=True, help_text='AI operation type', max_length=50)),
|
||||
('credits_cost', models.IntegerField(help_text='Credits required for this operation', validators=[django.core.validators.MinValueValidator(0)])),
|
||||
('unit', models.CharField(choices=[('per_request', 'Per Request'), ('per_100_words', 'Per 100 Words'), ('per_200_words', 'Per 200 Words'), ('per_item', 'Per Item'), ('per_image', 'Per Image')], default='per_request', help_text='What the cost applies to', max_length=50)),
|
||||
('display_name', models.CharField(help_text='Human-readable name', max_length=100)),
|
||||
('description', models.TextField(blank=True, help_text='What this operation does')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Enable/disable this operation')),
|
||||
('created_at', models.DateTimeField(blank=True, editable=False)),
|
||||
('updated_at', models.DateTimeField(blank=True, editable=False)),
|
||||
('previous_cost', models.IntegerField(blank=True, help_text='Cost before last update (for audit trail)', null=True)),
|
||||
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('history_date', models.DateTimeField(db_index=True)),
|
||||
('history_change_reason', models.CharField(max_length=100, null=True)),
|
||||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
|
||||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
('updated_by', models.ForeignKey(blank=True, db_constraint=False, help_text='Admin who last updated', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'historical Credit Cost Configuration',
|
||||
'verbose_name_plural': 'historical Credit Cost Configurations',
|
||||
'ordering': ('-history_date', '-history_id'),
|
||||
'get_latest_by': ('history_date', 'history_id'),
|
||||
},
|
||||
bases=(simple_history.models.HistoricalChanges, models.Model),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='HistoricalPayment',
|
||||
fields=[
|
||||
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
|
||||
('amount', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||
('currency', models.CharField(default='USD', max_length=3)),
|
||||
('status', models.CharField(choices=[('pending_approval', 'Pending Approval'), ('succeeded', 'Succeeded'), ('failed', 'Failed'), ('refunded', 'Refunded')], db_index=True, default='pending_approval', max_length=20)),
|
||||
('payment_method', models.CharField(choices=[('stripe', 'Stripe (Credit/Debit Card)'), ('paypal', 'PayPal'), ('bank_transfer', 'Bank Transfer (Manual)'), ('local_wallet', 'Local Wallet (Manual)'), ('manual', 'Manual Payment')], db_index=True, max_length=50)),
|
||||
('stripe_payment_intent_id', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('stripe_charge_id', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('paypal_order_id', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('paypal_capture_id', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('manual_reference', models.CharField(blank=True, help_text='Bank transfer reference, wallet transaction ID, etc.', max_length=255)),
|
||||
('manual_notes', models.TextField(blank=True, help_text='Admin notes for manual payments')),
|
||||
('admin_notes', models.TextField(blank=True, help_text='Internal notes on approval/rejection')),
|
||||
('approved_at', models.DateTimeField(blank=True, null=True)),
|
||||
('processed_at', models.DateTimeField(blank=True, null=True)),
|
||||
('failed_at', models.DateTimeField(blank=True, null=True)),
|
||||
('refunded_at', models.DateTimeField(blank=True, null=True)),
|
||||
('failure_reason', models.TextField(blank=True)),
|
||||
('metadata', models.JSONField(default=dict)),
|
||||
('created_at', models.DateTimeField(blank=True, editable=False)),
|
||||
('updated_at', models.DateTimeField(blank=True, editable=False)),
|
||||
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('history_date', models.DateTimeField(db_index=True)),
|
||||
('history_change_reason', models.CharField(max_length=100, null=True)),
|
||||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
|
||||
('account', models.ForeignKey(blank=True, db_column='tenant_id', db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='igny8_core_auth.account')),
|
||||
('approved_by', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
('invoice', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='billing.invoice')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'historical payment',
|
||||
'verbose_name_plural': 'historical payments',
|
||||
'ordering': ('-history_date', '-history_id'),
|
||||
'get_latest_by': ('history_date', 'history_id'),
|
||||
},
|
||||
bases=(simple_history.models.HistoricalChanges, models.Model),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user