Skip to content

Instantly share code, notes, and snippets.

@jasonleibowitz
Last active December 18, 2023 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonleibowitz/0255846255e777cd4aa808ffc75d2a1e to your computer and use it in GitHub Desktop.
Save jasonleibowitz/0255846255e777cd4aa808ffc75d2a1e to your computer and use it in GitHub Desktop.
For FundTerms that have a country set to "US", but missing domicile_country, backfill the domicile_country to "US".
from fund_admin.fund_admin.models import Fund
from fund_admin.fund_properties.amendable_properties.models import FundTerms
from fund_admin.fund_properties.amendable_properties.models import LPADocuments
terms = FundTerms.objects.filter(domicile_country__isnull=True, country__isnull=False, country="US").order_by('created_at')
print(f"Num Terms to Update: {terms.count()}")
if terms.count() > 0:
for term in terms:
lpa_document = LPADocuments.objects.get(pk=term.lpa_id)
fund_id = lpa_document.fund_id
fund = Fund.objects.get(pk=fund_id)
print(f"Setting domicile_country on fund ID: {fund.id} (Carta ID: {fund.carta_id}) - {fund.name} to {term.country}")
term.domicile_country = term.country
FundTerms.objects.bulk_update(terms, ["domicile_country"])
updated_terms = FundTerms.objects.filter(domicile_country__isnull=True, country__isnull=False, country="US").order_by('created_at')
print(f"Num Terms Post Run: {updated_terms.count()}")
@josephurschlercarta
Copy link

lgtm

@ian-busko-carta
Copy link

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment