diff --git a/scipost_django/finances/migrations/0033_populate_pubfracs.py b/scipost_django/finances/migrations/0033_populate_pubfracs.py index 17cec8580a14af4267e8434aba63db447f9d8c32..dd32182e8fdd8002a853a41178c9c1ea19e2234d 100644 --- a/scipost_django/finances/migrations/0033_populate_pubfracs.py +++ b/scipost_django/finances/migrations/0033_populate_pubfracs.py @@ -4,8 +4,20 @@ from django.db import migrations def populate_pubfracs(apps, schema_editor): - # OrgPubFraction = apps.get_model("journals.OrgPubFraction") - # PubFrac = apps.get_model("finances.PubFrac") + try: + OrgPubFraction = apps.get_model("journals.OrgPubFraction") + PubFrac = apps.get_model("finances.PubFrac") + + # Copy all data from OrgPubFraction to the new PubFrac + for opf in OrgPubFraction.objects.all(): + pubfrac = PubFrac( + organization=opf.organization, + publication=opf.publication, + fraction=opf.fraction, + ) + pubfrac.save() + except Exception as e: + print("Error populating PubFrac:", e) # # Copy all data from OrgPubFraction to the new PubFrac # for opf in OrgPubFraction.objects.all(): @@ -15,12 +27,13 @@ def populate_pubfracs(apps, schema_editor): # fraction=opf.fraction # ) # pubfrac.save() - pass # 2024-03-20 not needed anymore: PubFracs are algorithmically calculated + pass # 2024-03-20 not needed anymore: PubFracs are algorithmically calculated + class Migration(migrations.Migration): dependencies = [ - ('finances', '0032_pubfrac'), + ("finances", "0032_pubfrac"), ] operations = [