Skip to content

Commit

Permalink
Cleanup is_delisted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 29, 2024
1 parent f682fee commit 72de023
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions lemarche/siaes/management/commands/sync_with_emplois_inclusion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
from datetime import timedelta

from django.conf import settings
from django.contrib.gis.geos import GEOSGeometry
Expand Down Expand Up @@ -37,7 +36,6 @@
"admin_email",
"asp_id",
"is_active",
"is_delisted",
"c1_last_sync_date",
]

Expand Down Expand Up @@ -121,15 +119,12 @@ def handle(self, dry_run=False, **options):
# count before
siae_total_before = Siae.objects.all().count()
siae_active_before = Siae.objects.filter(is_active=True).count()
siae_delisted_before = Siae.objects.filter(is_delisted=True).count()

self.c4_update(c1_list_filtered, dry_run)
self.c4_delist_old_siae(dry_run)

# count after
siae_total_after = Siae.objects.all().count()
siae_active_after = Siae.objects.filter(is_active=True).count()
siae_delisted_after = Siae.objects.filter(is_delisted=True).count()

self.stdout_info("Done ! Some stats...")
created_count = siae_total_after - siae_total_before
Expand All @@ -140,7 +135,6 @@ def handle(self, dry_run=False, **options):
f"Siae updated: {updated_count}",
f"Siae active: before {siae_active_before} / after {siae_active_after}",
f"Siae inactive: before {siae_total_before - siae_active_before} / after {siae_total_after - siae_active_after}", # noqa
f"Siae delisted: before {siae_delisted_before} / after {siae_delisted_after}",
]
self.stdout_messages_success(msg_success)
api_slack.send_message_to_channel("\n".join(msg_success), service_id=settings.SLACK_WEBHOOK_C4_SUPPORT_CHANNEL)
Expand Down Expand Up @@ -174,11 +168,6 @@ def c1_export(self): # noqa C901
"c1_last_sync_date": timezone.now(),
}

# make sure that non active siae are delisted as well
# but done seperately, because some active siae can be delisted
if not c1_siae_cleaned["is_active"]:
c1_siae_cleaned["is_delisted"] = True

# set coords from latitude & longitude
c1_siae_cleaned["address"] = c1_siae_cleaned["address_line_1"]
if c1_siae_cleaned["address_line_2"]:
Expand Down Expand Up @@ -239,8 +228,6 @@ def c4_update(self, c1_list, dry_run):
except Siae.DoesNotExist:
self.c4_create_siae(c1_siae, dry_run)

self.c4_delist_old_siae(dry_run)

def c4_create_siae(self, c1_siae, dry_run):
"""
Here we create a new Siae with les-emplois data
Expand All @@ -256,9 +243,6 @@ def c4_create_siae(self, c1_siae, dry_run):
c1_siae["contact_email"] = c1_siae["admin_email"] or c1_siae["email"]
c1_siae["contact_phone"] = c1_siae["phone"]

# other fields
c1_siae["is_delisted"] = False

# create object
if not dry_run:
siae = Siae.objects.create(**c1_siae)
Expand All @@ -282,9 +266,6 @@ def c4_update_siae(self, c1_siae, c4_siae, dry_run):
Here we update an existing Siae with a subset of les-emplois data
"""
if not dry_run:
# other fields
# c1_siae["is_delisted"] = True if not c1_siae["convention_is_active"] else False

# keep only certain fields for update
c1_siae_filtered = dict()
for key in UPDATE_FIELDS:
Expand All @@ -293,16 +274,3 @@ def c4_update_siae(self, c1_siae, c4_siae, dry_run):

Siae.objects.filter(c1_id=c4_siae.c1_id).update(**c1_siae_filtered) # avoid updated_at change
# self.stdout_info(f"Siae updated / {c4_siae.id} / {c4_siae.siret}")

def c4_delist_old_siae(self, dry_run):
"""
Which Siae should we delist?
- the existing ones who haven't been updated
- all the ones who have is_active as False
"""
if not dry_run:
date_yesterday = timezone.now() - timedelta(days=1)
Siae.objects.exclude(c1_sync_skip=True).filter(c1_last_sync_date__lt=date_yesterday).update(
is_delisted=True
)
Siae.objects.filter(is_active=False).update(is_delisted=True)

0 comments on commit 72de023

Please sign in to comment.