send_reminders_for_unpaid_bills.py 934 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 add_arguments(self, parser):
  20. pass
  21. def handle(self, *args, **options):
  22. invoices = Invoice.objects.filter(status="open")
  23. for invoice in invoices:
  24. if not invoice.reminder_needed():
  25. continue
  26. invoice.send_reminder(auto=True)