payemnt billing and credits refactoring

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-20 07:39:51 +00:00
parent a97c72640a
commit bc50b022f1
34 changed files with 3028 additions and 307 deletions

View File

@@ -0,0 +1,55 @@
from datetime import timedelta
from django.db import migrations, models
from django.utils import timezone
def populate_invoice_type_and_expiry(apps, schema_editor):
Invoice = apps.get_model('billing', 'Invoice')
for invoice in Invoice.objects.all().iterator():
invoice_type = 'custom'
if getattr(invoice, 'subscription_id', None):
invoice_type = 'subscription'
else:
metadata = invoice.metadata or {}
if metadata.get('credit_package_id'):
invoice_type = 'credit_package'
invoice.invoice_type = invoice_type
if invoice_type == 'credit_package' and not invoice.expires_at:
base_time = invoice.created_at or timezone.now()
invoice.expires_at = base_time + timedelta(hours=48)
invoice.save(update_fields=['invoice_type', 'expires_at'])
def reverse_populate_invoice_type_and_expiry(apps, schema_editor):
Invoice = apps.get_model('billing', 'Invoice')
Invoice.objects.all().update(invoice_type='custom', expires_at=None)
class Migration(migrations.Migration):
dependencies = [
('billing', '0035_aimodelconfig_is_testing_and_more'),
]
operations = [
migrations.AddField(
model_name='invoice',
name='invoice_type',
field=models.CharField(choices=[('subscription', 'Subscription'), ('credit_package', 'Credit Package'), ('addon', 'Add-on'), ('custom', 'Custom')], db_index=True, default='custom', max_length=30),
),
migrations.AddField(
model_name='invoice',
name='expires_at',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='invoice',
name='void_reason',
field=models.TextField(blank=True),
),
migrations.RunPython(populate_invoice_type_and_expiry, reverse_populate_invoice_type_and_expiry),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.10 on 2026-01-20 06:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('billing', '0036_invoice_type_and_expiry'),
]
operations = [
migrations.AlterField(
model_name='creditpackage',
name='features',
field=models.JSONField(blank=True, default=list, help_text='Bonus features or highlights'),
),
migrations.AlterField(
model_name='planlimitusage',
name='limit_type',
field=models.CharField(choices=[('content_ideas', 'Content Ideas'), ('images_basic', 'Basic Images'), ('images_premium', 'Premium Images'), ('image_prompts', 'Image Prompts')], db_index=True, help_text='Type of limit being tracked', max_length=50),
),
]