def send_report(period_description, report_path, emails):
    email = AnymailMessage(
        subject=f'Prisoner money notifications for {period_description}',
        body=f"""
OFFICIAL SENSITIVE

Please find attached, the prisoner money notifications report for {period_description}.

There is a separate sheet for each notification rule for credits and disbursements.

The ‘Monitored by’ column that appears in some sheets is the number of users
who are monitoring that prisoner or payment source.

The ‘How many?’ column that appears in some sheets is the number that triggered
the rule in column A. For example, if the ‘How many?’ column says 4 for the rule
‘More than 2 credits from the same debit card or bank account to any prisoner in a week’,
then this means that a specific debit card or bank account sent 4 credits in a week
up to when that credit was sent.

If you have any queries, contact the team at {settings.TEAM_EMAIL}.
        """.strip(),
        from_email=default_from_address(),
        to=emails,
        tags=['notifications-report'],
    )
    email.attach_file(str(report_path), mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    email.send()
Ejemplo n.º 2
0
    def handle_prison(self, credit_notice_email, path, date, **options):
        call_command('create_prisoner_credit_notices',
                     path,
                     credit_notice_email.prison.nomis_id,
                     date=date,
                     **options)
        if not path.exists():
            if self.verbosity:
                self.stdout.write('Nothing to send to %s' %
                                  credit_notice_email)
            return

        template_context = {
            'static_url': urljoin(settings.SITE_URL, settings.STATIC_URL),
        }
        text_body = template_loader.get_template(
            'credit/prisoner-notice-email.txt').render(template_context)
        html_body = template_loader.get_template(
            'credit/prisoner-notice-email.html').render(template_context)
        email = AnymailMessage(
            subject=self.subject,
            body=text_body.strip('\n'),
            from_email=self.from_address,
            to=[credit_notice_email.email],
            tags=['prisoner-notice'],
        )
        email.attach_alternative(html_body, 'text/html')
        email.attach_file(str(path), mimetype='application/pdf')

        if self.verbosity:
            self.stdout.write('Sending prisoner notice email to %s' %
                              credit_notice_email)
        email.send()
    def handle_prison(self, credit_notice_email, path, date, **options):
        call_command(
            'create_prisoner_credit_notices',
            path, credit_notice_email.prison.nomis_id,
            date=date, **options
        )
        if not path.exists():
            if self.verbosity:
                self.stdout.write('Nothing to send to %s' % credit_notice_email)
            return

        template_context = prepare_context()
        text_body = template_loader.get_template('credit/prisoner-notice-email.txt').render(template_context)
        html_body = template_loader.get_template('credit/prisoner-notice-email.html').render(template_context)
        email = AnymailMessage(
            subject=str(self.subject),
            body=text_body.strip('\n'),
            from_email=self.from_address,
            to=[credit_notice_email.email],
            tags=['prisoner-notice'],
        )
        email.attach_alternative(html_body, 'text/html')
        email.attach_file(str(path), mimetype='application/pdf')

        if self.verbosity:
            self.stdout.write('Sending prisoner notice email to %s' % credit_notice_email)
        email.send()