def send_invoice_report(): """ Sends aggregate accounting data as CSV """ date = get_previous_month() subject = render_to_string( 'invoices/report_subject.txt', {'month': date.month, 'year': date.year,} ).strip() body = render_to_string( 'invoices/report_body.txt', {'month': date.month, 'year': date.year,} ).strip() filename = '3M%02d%dWaldur.txt' % (date.month, date.year) invoices = models.Invoice.objects.filter(year=date.year, month=date.month) # Report should include only organizations that had accounting running during the invoice period. if settings.WALDUR_CORE['ENABLE_ACCOUNTING_START_DATE']: invoices = invoices.filter( customer__accounting_start_date__lte=core_utils.month_end(date) ) # Report should not include customers with 0 invoice sum. invoices = [invoice for invoice in invoices if invoice.total > 0] text_message = format_invoice_csv(invoices) # Please note that email body could be empty if there are no valid invoices emails = [settings.WALDUR_INVOICES['INVOICE_REPORTING']['EMAIL']] logger.debug('About to send accounting report to {emails}'.format(emails=emails)) core_utils.send_mail_with_attachment( subject=subject, body=body, to=emails, attachment=text_message, filename=filename, )
def send_monthly_invoicing_reports_about_customers(): if settings.WALDUR_INVOICES['INVOICE_REPORTING']['ENABLE']: report = utils.get_monthly_invoicing_reports() pdf = pdfkit.from_string(report, False) today = timezone.datetime.today() filename = '%02d_%04d_invoice_report.pdf' % (today.month, today.year) subject = 'Financial report for %02d-%04d' % ( today.month, today.year, ) body = 'Financial report for %02d-%04d is attached.' % ( today.month, today.year, ) emails = [settings.WALDUR_INVOICES['INVOICE_REPORTING']['EMAIL']] core_utils.send_mail_with_attachment( subject=subject, body=body, to=emails, attachment=pdf, filename=filename, content_type='application/pdf', )