-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dépôt de besoin : envoi sondage transaction : mise en place de relanc…
…es (#1057) * Tender transaction survey: add reminder option * Update cron * Improve queryset
- Loading branch information
Showing
4 changed files
with
25 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 23 additions & 21 deletions
44
lemarche/tenders/management/commands/send_author_transactioned_question_emails.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
from datetime import datetime | ||
from datetime import datetime, timedelta | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from lemarche.tenders.models import Tender | ||
from lemarche.www.tenders.tasks import send_tenders_author_feedback_or_survey | ||
|
||
|
||
seven_days_ago = datetime.today().date() - timedelta(days=7) | ||
one_day_ago = datetime.today().date() - timedelta(days=1) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Daily script to send an email to tender authors | ||
When? J+7 after tender deadline_date | ||
When? | ||
- J+7 after tender deadline_date | ||
- Reminder: J+1 after tender start_working_date | ||
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 --reminder | ||
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", | ||
dest="is_all_tenders", | ||
"--reminder", | ||
dest="reminder", | ||
action="store_true", | ||
help="Send to all tenders with deadline_date 7 days ago", | ||
help="Send a second e-mail to authors who haven't responded to the first survey", | ||
) | ||
|
||
def handle(self, kind=None, dry_run=False, is_all_tenders=False, **options): | ||
self.stdout.write("-" * 80) | ||
def handle(self, kind=None, reminder=False, dry_run=False, **options): | ||
self.stdout.write("Script to send email transactioned_question for tenders...") | ||
|
||
self.stdout.write("-" * 80) | ||
start_date_feature = datetime(2022, 6, 23).date() | ||
# we first filter on validated tenders | ||
tender_qs = ( | ||
Tender.objects.sent() | ||
.transaction_survey_email(kind=kind, all=is_all_tenders) | ||
.filter(deadline_date__gte=start_date_feature) | ||
) | ||
tender_qs = Tender.objects.sent().filter(survey_transactioned_answer=None) | ||
if kind: | ||
tender_qs = tender_qs.filter(kind=kind) | ||
if reminder: | ||
tender_qs = tender_qs.exclude(survey_transactioned_send_date=None).filter(start_working_date=one_day_ago) | ||
else: | ||
tender_qs = tender_qs.filter(survey_transactioned_send_date=None).filter(deadline_date=seven_days_ago) | ||
|
||
self.stdout.write(f"Found {tender_qs.count()} tenders") | ||
|
||
if not dry_run: | ||
email_kind = f"transactioned_question_7d{'_reminder' if reminder else ''}" | ||
for tender in tender_qs: | ||
send_tenders_author_feedback_or_survey(tender, kind="transactioned_question_7d") | ||
self.stdout.write(f"Sent {tender_qs.count()} J+7 transactioned_question") | ||
|
||
self.stdout.write("-" * 80) | ||
self.stdout.write("Done!") | ||
send_tenders_author_feedback_or_survey(tender, kind=email_kind) | ||
self.stdout.write(f"Sent {tender_qs.count()} {email_kind}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters