def send_loan_overdue_reminder_mail(loan): """Send loan overdue email message async and log the result in Celery. :param loan: the overdue loan. """ send_loan_mail( "overdue_reminder", loan=loan, message_ctx=dict(days_ago=circulation_overdue_loan_days(loan)), )
def send_overdue_loans_mail_reminder(): """Send email message for loans that are overdue every X days.""" days = current_app.config["ILS_MAIL_LOAN_OVERDUE_REMINDER_INTERVAL"] loan_search = current_circulation.loan_search overdue_loans = loan_search.get_all_overdue_loans().execute() for hit in overdue_loans.hits: loan = hit.to_dict() overdue_days = circulation_overdue_loan_days(loan) if overdue_days % days == 0: send_loan_overdue_reminder_mail(loan)
def post(self, pid, record, **kwargs): """Loan email post method.""" days_ago = circulation_overdue_loan_days(record) is_overdue = days_ago > 0 if is_overdue: raise OverdueLoansMailError(description="This loan is not overdue") send_loan_overdue_reminder_mail(record, days_ago) return self.make_response(pid, record, 202, links_factory=self.links_factory)