Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear org country field #5781

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions temba/orgs/migrations/0166_clear_org_country_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.4 on 2025-01-09 17:51

from django.db import migrations


def clear_org_country_field(apps, schema_editor):
Org = apps.get_model("orgs", "Org")

orgs = Org.objects.all().exclude(country=None)
if orgs:
orgs.update(country=None)

Check warning on line 11 in temba/orgs/migrations/0166_clear_org_country_field.py

View check run for this annotation

Codecov / codecov/patch

temba/orgs/migrations/0166_clear_org_country_field.py#L11

Added line #L11 was not covered by tests


class Migration(migrations.Migration):

dependencies = [
("orgs", "0165_org_location"),
]

operations = [migrations.RunPython(clear_org_country_field, migrations.RunPython.noop)]
4 changes: 3 additions & 1 deletion temba/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ class Org(SmartModel):
default=DATE_FORMAT_DAY_FIRST,
help_text=_("Default formatting and parsing of dates in flows and messages."),
)
country = models.ForeignKey("locations.AdminBoundary", null=True, on_delete=models.PROTECT)
location = models.ForeignKey("locations.Location", null=True, on_delete=models.PROTECT)
flow_languages = ArrayField(models.CharField(max_length=3), default=list, validators=[ArrayMinLengthValidator(1)])
input_collation = models.CharField(max_length=32, choices=COLLATION_CHOICES, default=COLLATION_DEFAULT)
Expand Down Expand Up @@ -537,6 +536,9 @@ class Org(SmartModel):
released_on = models.DateTimeField(null=True)
deleted_on = models.DateTimeField(null=True)

# Deprecated
country = models.ForeignKey("locations.AdminBoundary", null=True, on_delete=models.PROTECT)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
6 changes: 3 additions & 3 deletions temba/utils/management/commands/mailroom_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from temba.contacts.models import Contact, ContactField, ContactGroup, ContactURN
from temba.flows.models import Flow
from temba.globals.models import Global
from temba.locations.models import AdminBoundary
from temba.locations.models import Location
from temba.msgs.models import Label
from temba.orgs.models import Org, OrgRole, User
from temba.templates.models import Template, TemplateTranslation
Expand Down Expand Up @@ -152,7 +152,7 @@ def load_locations(self, path):
# TODO figure out why this is needed
time.sleep(1)

return AdminBoundary.objects.filter(level=0).get()
return Location.objects.filter(level=0).get()

def reset_id_sequences(self, start: int):
with connection.cursor() as cursor:
Expand All @@ -167,7 +167,7 @@ def create_org(self, spec, superuser, country):
name=spec["name"],
timezone=ZoneInfo("America/Los_Angeles"),
flow_languages=spec["languages"],
country=country,
location=country,
created_on=timezone.now(),
created_by=superuser,
modified_by=superuser,
Expand Down
Binary file modified test-data/nigeria.bin
Binary file not shown.
Loading