send_reminders_for_unpaid_bills.py 883 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. # Standard python libs
  4. import logging
  5. # Django specific imports
  6. from argparse import RawTextHelpFormatter
  7. from django.core.management.base import BaseCommand, CommandError
  8. # Coin specific imports
  9. from coin.billing.models import Invoice
  10. class Command(BaseCommand):
  11. help = """
  12. Send a reminder to members for invoices which are due and not paid since a few
  13. weeks.
  14. """
  15. def create_parser(self, *args, **kwargs):
  16. parser = super(Command, self).create_parser(*args, **kwargs)
  17. parser.formatter_class = RawTextHelpFormatter
  18. return parser
  19. def handle(self, *args, **options):
  20. invoices = Invoice.objects.filter(status="open")
  21. for invoice in invoices:
  22. if not invoice.reminder_needed():
  23. continue
  24. invoice.send_reminder(auto=True)