@@ -0,0 +1,40 @@ +# Generated by Django 5.0.11 on 2026-01-21 12:18 +import math +from decimal import Decimal + +from django.db import migrations + + +def update_videos_quantity(apps, schema_editor): + VIDEO_MODELS = { + 'sora': Decimal('120'), + 'hailuo': Decimal('57'), + 'veo': Decimal('240'), + 'kling': Decimal('75'), + 'ray': Decimal('135'), + 'runway': Decimal('75'), + 'minimaxvideo': Decimal('150'), + 'hunyuan': Decimal('370'), + 'wan': Decimal('25'), + 'speedance': Decimal('9'), + } + + PaymentPlanFeature = apps.get_model('payments', 'PaymentPlanFeature') + payment_features = [] + + for feature in PaymentPlanFeature.objects.select_related('model', 'plan').filter(model__slug__in=VIDEO_MODELS.keys()): + feature.quantity = math.floor(feature.plan.tokens_per_plan / VIDEO_MODELS[feature.model.slug]) + payment_features.append(feature) + + PaymentPlanFeature.objects.bulk_update(payment_features, ['quantity']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('payments', '0023_reordering_payment_plan_features'), + ] + + operations = [ + migrations.RunPython(update_videos_quantity, migrations.RunPython.noop) + ]