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..4525fc140 --- /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_TENDER_SEND_AUTHOR_TRANSACTIONED_QUESTION_ENABLED" ]]; then + echo "CRON_TENDER_SEND_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 --kind QUOTE 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/siaes/management/commands/send_tenders_author_feedback.py b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py similarity index 70% 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..9a260a24c 100644 --- a/lemarche/siaes/management/commands/send_tenders_author_feedback.py +++ b/lemarche/tenders/management/commands/send_author_transactioned_question_emails.py @@ -4,20 +4,23 @@ 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): """ - 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 --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) @@ -47,7 +52,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)