diff --git a/clevercloud/cron.json b/clevercloud/cron.json index d87edd841..63360c8b0 100644 --- a/clevercloud/cron.json +++ b/clevercloud/cron.json @@ -8,6 +8,6 @@ "45 7 * * 1 $ROOT/clevercloud/siaes_update_api_qpv_fields.sh", "0 8 * * 1 $ROOT/clevercloud/siaes_update_api_zrr_fields.sh", "0 9 * * * $ROOT/clevercloud/siaes_send_user_request_reminders.sh", - "5 9 * * * $ROOT/clevercloud/tenders_send_siae_reminders.sh", + "5 9 * * * $ROOT/clevercloud/tenders_send_siae_contacted_reminders.sh", "10 9 * * * $ROOT/clevercloud/tenders_send_author_incremental.sh" ] \ No newline at end of file diff --git a/clevercloud/tenders_send_siae_reminder.sh b/clevercloud/tenders_send_siae_contacted_reminder.sh similarity index 60% rename from clevercloud/tenders_send_siae_reminder.sh rename to clevercloud/tenders_send_siae_contacted_reminder.sh index a88e88918..ec435ae74 100755 --- a/clevercloud/tenders_send_siae_reminder.sh +++ b/clevercloud/tenders_send_siae_contacted_reminder.sh @@ -3,8 +3,8 @@ # Send TenderSiae reminders # Do not run if this env var is not set: -if [[ -z "$CRON_TENDER_SEND_SIAE_REMINDERS_ENABLED" ]]; then - echo "CRON_TENDER_SEND_SIAE_REMINDERS_ENABLED not set. Exiting..." +if [[ -z "$CRON_TENDER_SEND_SIAE_CONTACTED_REMINDERS_ENABLED" ]]; then + echo "CRON_TENDER_SEND_SIAE_CONTACTED_REMINDERS_ENABLED not set. Exiting..." exit 0 fi @@ -19,4 +19,4 @@ fi # $APP_HOME is set by default by clever cloud. cd $APP_HOME -django-admin send_siae_reminder_emails --days-since-email-send-date 2 +django-admin send_siae_contacted_reminder_emails --days-since-email-send-date 2 diff --git a/lemarche/tenders/management/commands/send_siae_reminder_emails.py b/lemarche/tenders/management/commands/send_siae_contacted_reminder_emails.py similarity index 70% rename from lemarche/tenders/management/commands/send_siae_reminder_emails.py rename to lemarche/tenders/management/commands/send_siae_contacted_reminder_emails.py index deab19bd3..589e372af 100644 --- a/lemarche/tenders/management/commands/send_siae_reminder_emails.py +++ b/lemarche/tenders/management/commands/send_siae_contacted_reminder_emails.py @@ -4,7 +4,7 @@ from django.utils import timezone from lemarche.tenders.models import Tender, TenderSiae -from lemarche.www.tenders.tasks import send_tender_reminder_email_to_siaes +from lemarche.www.tenders.tasks import send_tender_contacted_reminder_email_to_siaes class Command(BaseCommand): @@ -13,10 +13,10 @@ class Command(BaseCommand): When? J+2 (but doesn't run on weekends!) Usage: - python manage.py send_siae_reminder_emails --dry-run - python manage.py send_siae_reminder_emails --days-since-email-send-date 2 - python manage.py send_siae_reminder_emails --tender-id 1 - python manage.py send_siae_reminder_emails + python manage.py send_siae_contacted_reminder_emails --dry-run + python manage.py send_siae_contacted_reminder_emails --days-since-email-send-date 2 + python manage.py send_siae_contacted_reminder_emails --tender-id 1 + python manage.py send_siae_contacted_reminder_emails """ def add_arguments(self, parser): @@ -51,29 +51,35 @@ def handle(self, dry_run=False, **options): # gte_days_ago = gte_days_ago+2 to account for Saturday & Sunday if current_weekday == 0: gte_days_ago = timezone.now() - timedelta(days=options["days_since_email_send_date"] + 1 + 2) - tendersiae_reminder_list = TenderSiae.objects.email_click_reminder( + tendersiae_contacted_reminder_list = TenderSiae.objects.email_click_reminder( gte_days_ago=gte_days_ago, lt_days_ago=lt_days_ago ) if options["tender_id"]: - tendersiae_reminder_list = tendersiae_reminder_list.filter(tender_id=options["tender_id"]) - self.stdout.write(f"Found {tendersiae_reminder_list.count()} TenderSiaes to remind") + tendersiae_contacted_reminder_list = tendersiae_contacted_reminder_list.filter( + tender_id=options["tender_id"] + ) + self.stdout.write(f"Found {tendersiae_contacted_reminder_list.count()} TenderSiaes to remind") if not dry_run: self.stdout.write("-" * 80) self.stdout.write("Step 2: Send emails for each tender") - tender_id_list = tendersiae_reminder_list.values_list("tender_id", flat=True).distinct().order_by() + tender_id_list = ( + tendersiae_contacted_reminder_list.values_list("tender_id", flat=True).distinct().order_by() + ) self.stdout.write(f"{tender_id_list.count()} tenders concerned") for tender_id in tender_id_list: tender = Tender.objects.get(id=tender_id) - tender_tendersiae_reminder_list = tendersiae_reminder_list.filter(tender_id=tender_id) + tender_tendersiae_contacted_reminder_list = tendersiae_contacted_reminder_list.filter( + tender_id=tender_id + ) tender_tendersiae = TenderSiae.objects.filter(tender_id=tender_id).filter( email_send_date__isnull=False ) self.stdout.write( - f"Tender {tender_id}: {tender_tendersiae_reminder_list.count()} TenderSiaes to remind (out of {tender_tendersiae.count()})" # noqa + f"Tender {tender_id}: {tender_tendersiae_contacted_reminder_list.count()} TenderSiaes to remind (out of {tender_tendersiae.count()})" # noqa ) - send_tender_reminder_email_to_siaes( + send_tender_contacted_reminder_email_to_siaes( tender, days_since_email_send_date=options["days_since_email_send_date"] ) self.stdout.write("Emails sent") diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index f4e04e4dd..c19c5b3d7 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -146,7 +146,9 @@ def send_tender_email_to_siae(tender: Tender, siae: Siae, email_subject: str, em ) -def send_tender_reminder_email_to_siaes(tender: Tender, days_since_email_send_date=2, send_on_weekends=False): +def send_tender_contacted_reminder_email_to_siaes( + tender: Tender, days_since_email_send_date=2, send_on_weekends=False +): email_subject = f"Un {tender.get_kind_display().lower()} pour vous sur le Marché de l'inclusion" current_weekday = timezone.now().weekday() @@ -157,26 +159,26 @@ def send_tender_reminder_email_to_siaes(tender: Tender, days_since_email_send_da if current_weekday == 0 and not send_on_weekends: # Monday: special case (need to account for Saturday & Sunday) gte_days_ago = timezone.now() - timedelta(days=days_since_email_send_date + 1 + 2) - tendersiae_reminder_list = TenderSiae.objects.filter(tender_id=tender.id).email_click_reminder( + tendersiae_contacted_reminder_list = TenderSiae.objects.filter(tender_id=tender.id).email_click_reminder( gte_days_ago=gte_days_ago, lt_days_ago=lt_days_ago ) - for tendersiae in tendersiae_reminder_list: + for tendersiae in tendersiae_contacted_reminder_list: # send to siae 'contact_email' - send_tender_reminder_email_to_siae(tendersiae, email_subject, days_since_email_send_date) + send_tender_contacted_reminder_email_to_siae(tendersiae, email_subject, days_since_email_send_date) # log email batch siaes_reminder_log_item = { "action": f"email_siaes_reminder_{days_since_email_send_date}d", "email_subject": email_subject, - "email_count": tendersiae_reminder_list.count(), + "email_count": tendersiae_contacted_reminder_list.count(), "email_timestamp": timezone.now().isoformat(), } tender.logs.append(siaes_reminder_log_item) tender.save() -def send_tender_reminder_email_to_siae(tendersiae: TenderSiae, email_subject, days_since_email_send_date): +def send_tender_contacted_reminder_email_to_siae(tendersiae: TenderSiae, email_subject, days_since_email_send_date): recipient_list = whitelist_recipient_list([tendersiae.siae.contact_email]) if recipient_list: recipient_email = recipient_list[0] if recipient_list else "" @@ -204,7 +206,7 @@ def send_tender_reminder_email_to_siae(tendersiae: TenderSiae, email_subject, da # log email log_item = { - "action": f"email_siae_reminder_{days_since_email_send_date}d", + "action": f"email_siae_contacted_reminder_{days_since_email_send_date}d", "email_to": recipient_email, "email_subject": email_subject, # "email_body": email_body,