-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58e5bcd
commit 4a94fce
Showing
10 changed files
with
325 additions
and
155 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
51 changes: 51 additions & 0 deletions
51
...tering_billing/migrations/0067_rename_customer_historicalinvoice_old_customer_and_more.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,51 @@ | ||
# Generated by Django 4.0.5 on 2022-11-10 21:00 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("metering_billing", "0066_change_unique_rate_to_count"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="historicalinvoice", | ||
old_name="customer", | ||
new_name="old_customer", | ||
), | ||
migrations.RenameField( | ||
model_name="historicalinvoice", | ||
old_name="organization", | ||
new_name="old_organization", | ||
), | ||
migrations.RenameField( | ||
model_name="historicalinvoice", | ||
old_name="subscription", | ||
new_name="old_subscription", | ||
), | ||
migrations.RenameField( | ||
model_name="invoice", | ||
old_name="customer", | ||
new_name="old_customer", | ||
), | ||
migrations.RenameField( | ||
model_name="invoice", | ||
old_name="organization", | ||
new_name="old_organization", | ||
), | ||
migrations.RenameField( | ||
model_name="invoice", | ||
old_name="subscription", | ||
new_name="old_subscription", | ||
), | ||
migrations.RemoveField( | ||
model_name="historicalinvoice", | ||
name="external_payment_obj", | ||
), | ||
migrations.RemoveField( | ||
model_name="invoice", | ||
name="external_payment_obj", | ||
), | ||
] |
83 changes: 83 additions & 0 deletions
83
backend/metering_billing/migrations/0068_historicalinvoice_customer_and_more.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,83 @@ | ||
# Generated by Django 4.0.5 on 2022-11-10 21:01 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"metering_billing", | ||
"0067_rename_customer_historicalinvoice_old_customer_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="historicalinvoice", | ||
name="customer", | ||
field=models.ForeignKey( | ||
blank=True, | ||
db_constraint=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="+", | ||
to="metering_billing.customer", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="historicalinvoice", | ||
name="organization", | ||
field=models.ForeignKey( | ||
blank=True, | ||
db_constraint=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="+", | ||
to="metering_billing.organization", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="historicalinvoice", | ||
name="subscription", | ||
field=models.ForeignKey( | ||
blank=True, | ||
db_constraint=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="+", | ||
to="metering_billing.subscription", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="invoice", | ||
name="customer", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="invoices", | ||
to="metering_billing.customer", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="invoice", | ||
name="organization", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="invoices", | ||
to="metering_billing.organization", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="invoice", | ||
name="subscription", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="invoices", | ||
to="metering_billing.subscription", | ||
), | ||
), | ||
] |
72 changes: 72 additions & 0 deletions
72
backend/metering_billing/migrations/0069_transfer_invoice_to_fk.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,72 @@ | ||
# Generated by Django 4.0.5 on 2022-11-10 21:02 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def migrate_jsonfields_to_fk(apps, schema_editor): | ||
Invoice = apps.get_model("metering_billing", "Invoice") | ||
Organization = apps.get_model("metering_billing", "Organization") | ||
Subscription = apps.get_model("metering_billing", "Subscription") | ||
Customer = apps.get_model("metering_billing", "Customer") | ||
|
||
invoice_org_dict = {} | ||
invoice_customer_dict = {} | ||
invoice_sub_dict = {} | ||
for invoice in Invoice.objects.all(): | ||
try: | ||
invoice_org = invoice.old_organization["company_name"] | ||
except: | ||
print(invoice.__dict__) | ||
raise | ||
invoice_customer = invoice.old_customer["customer_id"] | ||
invoice_sub = invoice.old_subscription["subscription_id"] | ||
|
||
if invoice_org in invoice_org_dict: | ||
invoice_org_object = invoice_org_dict[invoice_org] | ||
else: | ||
try: | ||
invoice_org_object = Organization.objects.get(company_name=invoice_org) | ||
except Organization.DoesNotExist: | ||
invoice_org_object = None | ||
print(f"Invoice {invoice.pk} has no organization") | ||
invoice_org_dict[invoice_org] = invoice_org_object | ||
invoice.organization = invoice_org_object | ||
|
||
if invoice_customer in invoice_customer_dict: | ||
invoice_customer_object = invoice_customer_dict[invoice_customer] | ||
else: | ||
try: | ||
invoice_customer_object = Customer.objects.get( | ||
organization=invoice_org_object, customer_id=invoice_customer | ||
) | ||
except: | ||
invoice_customer_object = None | ||
print(f"Invoice {invoice.pk} has no customer") | ||
invoice_customer_dict[invoice_customer] = invoice_customer_object | ||
invoice.customer = invoice_customer_object | ||
|
||
if invoice_sub in invoice_sub_dict: | ||
invoice_sub_object = invoice_sub_dict[invoice_sub] | ||
else: | ||
try: | ||
invoice_sub_object = Subscription.objects.get( | ||
organization=invoice_org_object, subscription_id=invoice_sub | ||
) | ||
except: | ||
invoice_sub_object = None | ||
print(f"Invoice {invoice.pk} has no subscription") | ||
invoice_sub_dict[invoice_sub] = invoice_sub_object | ||
invoice.subscription = invoice_sub_object | ||
|
||
invoice.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("metering_billing", "0068_historicalinvoice_customer_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_jsonfields_to_fk), | ||
] |
37 changes: 37 additions & 0 deletions
37
backend/metering_billing/migrations/0070_remove_historicalinvoice_old_customer_and_more.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,37 @@ | ||
# Generated by Django 4.0.5 on 2022-11-10 21:22 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("metering_billing", "0069_transfer_invoice_to_fk"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="historicalinvoice", | ||
name="old_customer", | ||
), | ||
migrations.RemoveField( | ||
model_name="historicalinvoice", | ||
name="old_organization", | ||
), | ||
migrations.RemoveField( | ||
model_name="historicalinvoice", | ||
name="old_subscription", | ||
), | ||
migrations.RemoveField( | ||
model_name="invoice", | ||
name="old_customer", | ||
), | ||
migrations.RemoveField( | ||
model_name="invoice", | ||
name="old_organization", | ||
), | ||
migrations.RemoveField( | ||
model_name="invoice", | ||
name="old_subscription", | ||
), | ||
] |
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
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
Oops, something went wrong.