Skip to content

Commit

Permalink
fix: include STARTED status for external onboarding reminder
Browse files Browse the repository at this point in the history
  • Loading branch information
yolile committed Oct 31, 2024
1 parent 6c6eb6d commit 63c9807
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 9 additions & 1 deletion app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,16 @@ def send_reminders() -> None:

@app.command()
def sync_applications_with_external_onboarding() -> None:
"""
Email borrowers who have selected a lender with an external onboarding system to remind them to start the
onboarding process.
Use this command
"""
with contextmanager(get_db)() as session:
for application in models.Application.pending_external_onboarding(session, models.ApplicationStatus.STARTED):
for application in models.Application.pending_external_onboarding(
session, (models.ApplicationStatus.STARTED,)
):
mail.send(session, aws.ses_client, models.MessageType.BORROWER_EXTERNAL_ONBOARDING_REMINDER, application)

session.commit()
Expand Down
10 changes: 6 additions & 4 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class MessageType(StrEnum):
BORROWER_PENDING_SUBMIT_REMINDER = "BORROWER_PENDING_SUBMIT_REMINDER"
#: Remind the borrower to start external onboarding.
#:
#: SUBMITTED (:typer:`python-m-app-send-reminders`)
#: SUBMITTED, STARTED (:typer:`python-m-app-send-reminders`)
BORROWER_EXTERNAL_ONBOARDING_REMINDER = "BORROWER_EXTERNAL_ONBOARDING_REMINDER"
#: Confirm receipt of the application.
#:
Expand Down Expand Up @@ -766,22 +766,24 @@ def pending_external_onboarding_reminder(cls, session: Session) -> "Query[Self]"
lapsed_at = col(cls.borrower_submitted_at) + timedelta(days=app_settings.days_to_change_to_lapsed)
days = app_settings.reminder_days_before_lapsed_for_external_onboarding

return cls.pending_external_onboarding(session, ApplicationStatus.SUBMITTED).filter(
return cls.pending_external_onboarding(
session, (ApplicationStatus.SUBMITTED, ApplicationStatus.STARTED)
).filter(
datetime.now() < lapsed_at,
lapsed_at <= datetime.now() + timedelta(days=days),
col(cls.id).notin_(Message.application_by_type(MessageType.BORROWER_EXTERNAL_ONBOARDING_REMINDER)),
)

@classmethod
def pending_external_onboarding(cls, session: Session, status: ApplicationStatus) -> "Query[Self]":
def pending_external_onboarding(cls, session: Session, statuses: tuple[ApplicationStatus, ...]) -> "Query[Self]":
"""
Return a query for applications with the provided status, in which the lender uses external onboarding, and
whose borrower hasn't already started external onboarding.
"""
return (
session.query(cls)
.filter(
cls.status == status,
col(cls.status).in_(statuses),
col(Lender.external_onboarding_url) != "",
col(cls.borrower_accessed_external_onboarding_at).is_(None),
)
Expand Down

0 comments on commit 63c9807

Please sign in to comment.