From 925096611deb7384372f85771e0ac9ea87f7c8a0 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 21 Aug 2023 12:40:58 +0200 Subject: [PATCH 1/4] Rename unused existing management command --- .../commands/send_author_transactioned_question_emails.py} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename lemarche/{siaes/management/commands/send_tenders_author_feedback.py => tenders/management/commands/send_author_transactioned_question_emails.py} (91%) diff --git a/lemarche/siaes/management/commands/send_tenders_author_feedback.py b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py similarity index 91% rename from lemarche/siaes/management/commands/send_tenders_author_feedback.py rename to lemarche/tenders/management/commands/send_author_transactioned_question_emails.py index b5eabba85..efe617c70 100644 --- a/lemarche/siaes/management/commands/send_tenders_author_feedback.py +++ b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py @@ -9,12 +9,12 @@ class Command(BaseCommand): """ - Daily script to send email feedback for tenders + Daily script to send an email to tender authors When? J+30 after validation of tenders Usage: - python manage.py send_user_tenders_feedback --dry-run - python manage.py send_user_tenders_feedback + python manage.py send_author_transactioned_question_emails --dry-run + python manage.py send_author_transactioned_question_emails """ def add_arguments(self, parser): From bfbf9ce93140e8dc1a3db4df9ad600c0b94a6f8f Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 21 Aug 2023 12:56:55 +0200 Subject: [PATCH 2/4] Update task --- config/settings/base.py | 3 +++ .../send_author_transactioned_question_emails.py | 4 ++-- lemarche/www/tenders/tasks.py | 11 ++++++++--- lemarche/www/tenders/tests.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index 837153aa5..699193988 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -368,6 +368,9 @@ "MAILJET_TENDERS_AUTHOR_INCREMENTAL_2D_TEMPLATE_ID", 4585824 ) MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID = env.int("MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID", 4017446) +MAILJET_TENDERS_AUTHOR_TRANSACTIONED_QUESTION_30D_TEMPLATE_ID = env.int( + "MAILJET_TENDERS_AUTHOR_TRANSACTIONED_QUESTION_30D_TEMPLATE_ID", 4951625 +) # -- Sendinblue (BREVO) diff --git a/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py index efe617c70..b2a4f6d4c 100644 --- a/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py +++ b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py @@ -4,7 +4,7 @@ from django.db.models import Q from lemarche.tenders.models import Tender -from lemarche.www.tenders.tasks import send_tenders_author_feedback_30_days +from lemarche.www.tenders.tasks import send_tenders_author_30_days class Command(BaseCommand): @@ -47,7 +47,7 @@ def handle(self, dry_run=False, is_all_tenders=False, **options): if not dry_run: for tender in tenders_for_feedbacks: - send_tenders_author_feedback_30_days(tender) + send_tenders_author_30_days(tender, kind="transactioned_question") self.stdout.write(f"Sent {tenders_for_feedbacks.count()} J+30 feedbacks") self.stdout.write("-" * 80) diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index d531d022b..7454a9d65 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -484,7 +484,7 @@ def send_author_incremental_2_days_email(tender: Tender): tender.save() -def send_tenders_author_feedback_30_days(tender: Tender): +def send_tenders_author_30_days(tender: Tender, kind="feedback"): email_subject = f"Concernant votre {tender.get_kind_display()} sur le Marché de l'inclusion" recipient_list = whitelist_recipient_list([tender.author.email]) if recipient_list: @@ -498,8 +498,13 @@ def send_tenders_author_feedback_30_days(tender: Tender): "TENDER_KIND": tender.get_kind_display(), } + if kind == "transactioned_question": + template_id = settings.MAILJET_TENDERS_AUTHOR_TRANSACTIONED_QUESTION_30D_TEMPLATE_ID + else: + template_id = settings.MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID + api_mailjet.send_transactional_email_with_template( - template_id=settings.MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID, + template_id=template_id, subject=email_subject, recipient_email=recipient_email, recipient_name=recipient_name, @@ -508,7 +513,7 @@ def send_tenders_author_feedback_30_days(tender: Tender): # log email log_item = { - "action": "email_feedback_30d_sent", + "action": f"email_{kind}_30d_sent", "email_to": recipient_email, "email_subject": email_subject, # "email_body": email_body, diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index cdc5999bc..8387a97c4 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -873,7 +873,7 @@ def test_update_tendersiae_stats_on_tender_contact_click(self): # def test_send_email_for_feedbacks_set_log(self): # self.assertEqual(len(self.tender.logs), 0) -# send_tenders_author_feedback_30_days(self.tender) +# send_tenders_author_30_days(self.tender, kind="feedback") # # fetch tender to be sure to have the last version of tender # tender: Tender = Tender.objects.get(pk=self.tender.pk) # self.assertEqual(len(tender.logs), 1) From 4ff499b96c4e57489d829889a79f3401c41f5147 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 21 Aug 2023 12:59:53 +0200 Subject: [PATCH 3/4] Add to cron --- clevercloud/cron.json | 1 + ...nd_author_transactioned_question_emails.sh | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 clevercloud/tenders_send_author_transactioned_question_emails.sh diff --git a/clevercloud/cron.json b/clevercloud/cron.json index 4aa0e01a9..3f84829f3 100644 --- a/clevercloud/cron.json +++ b/clevercloud/cron.json @@ -9,6 +9,7 @@ "40 7 * * 1 $ROOT/clevercloud/siaes_update_api_zrr_fields.sh", "0 7 * * 2 $ROOT/clevercloud/siaes_send_completion_reminder_emails.sh", "0 8 * * * $ROOT/clevercloud/siaes_send_user_request_reminder_emails.sh", + "30 8 * * * $ROOT/clevercloud/tenders_send_author_transactioned_question_emails.sh", "0 9 * * * $ROOT/clevercloud/tenders_send_siae_contacted_reminder_emails.sh", "10 9 * * * $ROOT/clevercloud/tenders_send_siae_interested_reminder_emails.sh", "20 9 * * * $ROOT/clevercloud/tenders_send_author_incremental.sh" diff --git a/clevercloud/tenders_send_author_transactioned_question_emails.sh b/clevercloud/tenders_send_author_transactioned_question_emails.sh new file mode 100755 index 000000000..335122779 --- /dev/null +++ b/clevercloud/tenders_send_author_transactioned_question_emails.sh @@ -0,0 +1,22 @@ +#!/bin/bash -l + +# Send email for tender transactioned question to author + +# Do not run if this env var is not set: +if [[ -z "$CRON_SEND_TENDER_AUTHOR_TRANSACTIONED_QUESTION_ENABLED" ]]; then + echo "CRON_SEND_TENDER_AUTHOR_TRANSACTIONED_QUESTION_ENABLED not set. Exiting..." + exit 0 +fi + +# About clever cloud cronjobs: +# https://www.clever-cloud.com/doc/tools/crons/ + +if [[ "$INSTANCE_NUMBER" != "0" ]]; then + echo "Instance number is ${INSTANCE_NUMBER}. Stop here." + exit 0 +fi + +# $APP_HOME is set by default by clever cloud. +cd $APP_HOME + +django-admin send_author_transactioned_question_emails From 213cb3adfe607e6a3e620fcbf4f5957796be5222 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 21 Aug 2023 15:17:16 +0200 Subject: [PATCH 4/4] add filter on quotes --- .../tenders_send_author_transactioned_question_emails.sh | 6 +++--- .../commands/send_author_transactioned_question_emails.py | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clevercloud/tenders_send_author_transactioned_question_emails.sh b/clevercloud/tenders_send_author_transactioned_question_emails.sh index 335122779..4525fc140 100755 --- a/clevercloud/tenders_send_author_transactioned_question_emails.sh +++ b/clevercloud/tenders_send_author_transactioned_question_emails.sh @@ -3,8 +3,8 @@ # Send email for tender transactioned question to author # Do not run if this env var is not set: -if [[ -z "$CRON_SEND_TENDER_AUTHOR_TRANSACTIONED_QUESTION_ENABLED" ]]; then - echo "CRON_SEND_TENDER_AUTHOR_TRANSACTIONED_QUESTION_ENABLED not set. Exiting..." +if [[ -z "$CRON_TENDER_SEND_AUTHOR_TRANSACTIONED_QUESTION_ENABLED" ]]; then + echo "CRON_TENDER_SEND_AUTHOR_TRANSACTIONED_QUESTION_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_author_transactioned_question_emails +django-admin send_author_transactioned_question_emails --kind QUOTE diff --git a/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py index b2a4f6d4c..9a260a24c 100644 --- a/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py +++ b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py @@ -14,10 +14,13 @@ class Command(BaseCommand): Usage: python manage.py send_author_transactioned_question_emails --dry-run + python manage.py send_author_transactioned_question_emails --all + python manage.py send_author_transactioned_question_emails --kind QUOTE python manage.py send_author_transactioned_question_emails """ def add_arguments(self, parser): + parser.add_argument("--kind", type=str, dest="kind") parser.add_argument("--dry-run", dest="dry_run", action="store_true", help="Dry run, no sends") parser.add_argument( "--all", @@ -26,13 +29,15 @@ def add_arguments(self, parser): help="Send to all tenders validated 30 days ago or more", ) - def handle(self, dry_run=False, is_all_tenders=False, **options): + def handle(self, kind=None, dry_run=False, is_all_tenders=False, **options): self.stdout.write("-" * 80) self.stdout.write("Script to send email feedback for tenders...") self.stdout.write("-" * 80) thirty_days_ago = datetime.today().date() - timedelta(days=30) tenders_validated = Tender.objects.validated() + if kind: + tenders_validated = tenders_validated.filter(kind=kind) if is_all_tenders: # all tenders validated 30 days ago or more tenders_for_feedbacks = tenders_validated.filter(validated_at__date__lte=thirty_days_ago)