-
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.
✨(backend) send email reminder of upcoming debit installment
The new django command `send_mail_upcoming_debit` will retrieve all 'pending' state installments on orders payment schedules and send a reminder email with a certain amount of days in advance (configured with `JOANIE_INSTALLMENT_REMINDER_PERIOD_DAYS`) to the order's owner notifying them that they will be debited on their credit card. Fix #864
- Loading branch information
1 parent
d5e4f4a
commit 4df154f
Showing
9 changed files
with
692 additions
and
15 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
56 changes: 56 additions & 0 deletions
56
src/backend/joanie/core/management/commands/send_mail_upcoming_debit.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Management command to send a reminder email to the order's owner on next installment to pay""" | ||
|
||
import logging | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.core.management import BaseCommand | ||
from django.utils import timezone | ||
|
||
from joanie.core.models import Order | ||
from joanie.core.tasks.payment_schedule import send_mail_reminder_installment_debit_task | ||
from joanie.core.utils.payment_schedule import is_next_installment_to_debit | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Command to send an email to the order's owner notifying them that an upcoming | ||
installment debit from their payment schedule will be debited soon on their credit card. | ||
""" | ||
|
||
help = __doc__ | ||
|
||
def handle(self, *args, **options): | ||
""" | ||
Retrieve all upcoming pending payment schedules depending on the target due date and | ||
send an email reminder to the order's owner who will be soon debited. | ||
""" | ||
logger.info( | ||
"Starting processing order payment schedule for upcoming installments." | ||
) | ||
due_date = ( | ||
timezone.localdate().date() | ||
+ timedelta(days=settings.JOANIE_INSTALLMENT_REMINDER_PERIOD_DAYS) | ||
).isoformat() | ||
|
||
found_orders_count = 0 | ||
sent_email_count = 0 | ||
for order in Order.objects.find_pending_installments().iterator(): | ||
for installment in order.payment_schedule: | ||
if is_next_installment_to_debit( | ||
installment=installment, due_date=due_date | ||
): | ||
logger.info("Sending reminder mail for order %s.", order.id) | ||
send_mail_reminder_installment_debit_task.delay( | ||
order_id=order.id, installment_id=installment["id"] | ||
) | ||
sent_email_count += 1 | ||
found_orders_count += 1 | ||
|
||
logger.info( | ||
"Found %s upcoming 'pending' installment and %s mails sent", | ||
found_orders_count, | ||
sent_email_count, | ||
) |
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
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
Oops, something went wrong.