fina autoamtiona adn billing and credits

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-04 15:54:15 +00:00
parent f8a9293196
commit 40dfe20ead
40 changed files with 5680 additions and 18 deletions

View File

@@ -0,0 +1,99 @@
# Generated by Django for IGNY8 Billing App
# Date: December 4, 2025
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='CreditTransaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('transaction_type', models.CharField(
choices=[
('purchase', 'Purchase'),
('deduction', 'Deduction'),
('refund', 'Refund'),
('grant', 'Grant'),
('adjustment', 'Manual Adjustment'),
],
max_length=20
)),
('amount', models.IntegerField(help_text='Positive for additions, negative for deductions')),
('balance_after', models.IntegerField(help_text='Account balance after this transaction')),
('description', models.CharField(max_length=255)),
('metadata', models.JSONField(default=dict, help_text='Additional transaction details')),
('created_at', models.DateTimeField(auto_now_add=True)),
('account', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='credit_transactions',
to=settings.AUTH_USER_MODEL
)),
],
options={
'verbose_name': 'Credit Transaction',
'verbose_name_plural': 'Credit Transactions',
'db_table': 'igny8_credit_transactions',
'ordering': ['-created_at'],
'indexes': [
models.Index(fields=['account', '-created_at'], name='idx_credit_txn_account_date'),
models.Index(fields=['transaction_type'], name='idx_credit_txn_type'),
],
},
),
migrations.CreateModel(
name='CreditUsageLog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('operation_type', models.CharField(
choices=[
('clustering', 'Clustering'),
('idea_generation', 'Idea Generation'),
('content_generation', 'Content Generation'),
('image_generation', 'Image Generation'),
('image_prompt_extraction', 'Image Prompt Extraction'),
('taxonomy_generation', 'Taxonomy Generation'),
('content_rewrite', 'Content Rewrite'),
('keyword_research', 'Keyword Research'),
('site_page_generation', 'Site Page Generation'),
],
max_length=50
)),
('credits_used', models.IntegerField()),
('cost_usd', models.DecimalField(decimal_places=2, max_digits=10, null=True, blank=True)),
('model_used', models.CharField(max_length=100, blank=True)),
('tokens_input', models.IntegerField(null=True, blank=True)),
('tokens_output', models.IntegerField(null=True, blank=True)),
('related_object_type', models.CharField(max_length=50, blank=True)),
('related_object_id', models.IntegerField(null=True, blank=True)),
('metadata', models.JSONField(default=dict)),
('created_at', models.DateTimeField(auto_now_add=True)),
('account', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='credit_usage_logs',
to=settings.AUTH_USER_MODEL
)),
],
options={
'verbose_name': 'Credit Usage Log',
'verbose_name_plural': 'Credit Usage Logs',
'db_table': 'igny8_credit_usage_logs',
'ordering': ['-created_at'],
'indexes': [
models.Index(fields=['account', '-created_at'], name='idx_credit_usage_account_date'),
models.Index(fields=['operation_type'], name='idx_credit_usage_operation'),
],
},
),
]

View File

@@ -0,0 +1,89 @@
# Generated by Django for IGNY8 Billing App
# Date: December 4, 2025
# Adds CreditCostConfig model for database-driven credit cost configuration
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('billing', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='CreditCostConfig',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('operation_type', models.CharField(
choices=[
('clustering', 'Auto Clustering'),
('idea_generation', 'Idea Generation'),
('content_generation', 'Content Generation'),
('image_generation', 'Image Generation'),
('image_prompt_extraction', 'Image Prompt Extraction'),
('taxonomy_generation', 'Taxonomy Generation'),
('content_rewrite', 'Content Rewrite'),
('keyword_research', 'Keyword Research'),
('site_page_generation', 'Site Page Generation'),
],
help_text='AI operation type',
max_length=50,
unique=True
)),
('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_image', 'Per Image'),
('per_item', 'Per Item'),
('per_keyword', 'Per Keyword'),
],
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')),
('previous_cost', models.IntegerField(
blank=True,
help_text='Cost before last update (for audit trail)',
null=True
)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('updated_by', models.ForeignKey(
blank=True,
help_text='Admin who last updated',
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='credit_cost_updates',
to=settings.AUTH_USER_MODEL
)),
],
options={
'verbose_name': 'Credit Cost Configuration',
'verbose_name_plural': 'Credit Cost Configurations',
'db_table': 'igny8_credit_cost_config',
'ordering': ['operation_type'],
},
),
migrations.AddIndex(
model_name='creditcostconfig',
index=models.Index(fields=['operation_type'], name='idx_credit_cost_op'),
),
migrations.AddIndex(
model_name='creditcostconfig',
index=models.Index(fields=['is_active'], name='idx_credit_cost_active'),
),
]

View File

@@ -0,0 +1 @@
# Billing app migrations