Skip to content

Commit

Permalink
feat: consolidate past payments data
Browse files Browse the repository at this point in the history
Move all past payments to current service customer.
  • Loading branch information
nijel committed Dec 18, 2024
1 parent b221a6b commit 5820cce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ max-complexity = 16
[tool.ruff.lint.per-file-ignores]
"scripts/*" = ["T201"]
"weblate_web/migrations/0031_fill_in_customer.py" = ["T201"]
"weblate_web/migrations/0038_migrate_payments.py" = ["T201"]
"weblate_web/payments/backends.py" = ["T201"]
"weblate_web/payments/migrations/0040_fill_in_users.py" = ["T201"]
31 changes: 31 additions & 0 deletions weblate_web/migrations/0038_migrate_payments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.1.3 on 2024-12-18 11:45

from django.db import migrations


def migrate_payments(payments, customer):
print(f"Moving {len(payments)} payments to {customer.name}")
payments.update(customer=customer)


def update_payments(apps, schema_editor):
Subscription = apps.get_model("weblate_web", "Subscription")
Payment = apps.get_model("payments", "Payment")

for subscription in Subscription.objects.prefetch_related("pastpayments_set"):
payment_ids = {subscription.payment}
payment_ids.update(past.payment for past in subscription.pastpayments_set.all())
migrate_payments(
Payment.objects.filter(pk__in=payment_ids), subscription.service.customer
)


class Migration(migrations.Migration):
dependencies = [
("weblate_web", "0037_package_hidden"),
("payments", "0037_alter_customer_vat"),
]

operations = [
migrations.RunPython(update_payments, migrations.RunPython.noop, elidable=True),
]

0 comments on commit 5820cce

Please sign in to comment.