-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move txn migration to a separate script
- Loading branch information
Showing
3 changed files
with
39 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app_users/migrations/0019_alter_appusertransaction_reason.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.7 on 2024-07-14 21:40 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app_users', '0018_appusertransaction_plan_appusertransaction_reason'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='appusertransaction', | ||
name='reason', | ||
field=models.IntegerField(choices=[(1, 'Deduct'), (2, 'Addon'), (3, 'Subscribe'), (4, 'Sub-Create'), (5, 'Sub-Cycle'), (6, 'Sub-Update'), (7, 'Auto-Recharge')], help_text='The reason for this transaction.<br><br>Deduct: Credits deducted due to a run.<br>Addon: User purchased an add-on.<br>Subscribe: Applies to subscriptions where no distinction was made between create, update and cycle.<br>Sub-Create: A subscription was created.<br>Sub-Cycle: A subscription advanced into a new period.<br>Sub-Update: A subscription was updated.<br>Auto-Recharge: Credits auto-recharged due to low balance.'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from app_users.models import TransactionReason, AppUserTransaction | ||
from payments.plans import PricingPlan | ||
|
||
|
||
def run(): | ||
for transaction in AppUserTransaction.objects.filter(amount__gt=0): | ||
# For old transactions, we didn't have a subscription field. | ||
# It just so happened that all monthly subscriptions we offered had | ||
# different amounts from the one-time purchases. | ||
# This uses that heuristic to determine whether a transaction | ||
# was a subscription payment or a one-time purchase. | ||
transaction.reason = TransactionReason.ADDON | ||
for plan in PricingPlan: | ||
if ( | ||
transaction.amount == plan.credits | ||
and transaction.charged_amount == plan.monthly_charge * 100 | ||
): | ||
transaction.plan = plan.db_value | ||
transaction.reason = TransactionReason.SUBSCRIBE | ||
break | ||
transaction.save(update_fields=["reason", "plan"]) |