|
@@ -1,5 +1,7 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
import datetime
|
|
|
+
|
|
|
+from argparse import RawTextHelpFormatter
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
from django.conf import settings
|
|
|
|
|
@@ -8,13 +10,39 @@ from coin.billing.create_subscriptions_invoices import create_all_members_invoic
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
- args = '[date=2011-07-04]'
|
|
|
+
|
|
|
help = 'Create invoices for members subscriptions for date specified (or today if no date passed)'
|
|
|
|
|
|
+ def create_parser(self, *args, **kwargs):
|
|
|
+ parser = super(Command, self).create_parser(*args, **kwargs)
|
|
|
+ parser.formatter_class = RawTextHelpFormatter
|
|
|
+ return parser
|
|
|
+
|
|
|
+ def add_arguments(self, parser):
|
|
|
+
|
|
|
+ parser.add_argument(
|
|
|
+ 'date',
|
|
|
+ type=str,
|
|
|
+ help="The date for the period for which to charge subscription (e.g. 2011-07-04)"
|
|
|
+ )
|
|
|
+
|
|
|
+ parser.add_argument(
|
|
|
+ '--antidate',
|
|
|
+ action='store_true',
|
|
|
+ dest='antidate',
|
|
|
+ default=False,
|
|
|
+ help="'Antidate' invoices, in the sense that invoices won't be validated with today's date but using the date of the end of the service. Meant to be use to charge subscription from a few months in the past..."
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def handle(self, *args, **options):
|
|
|
verbosity = int(options['verbosity'])
|
|
|
+ antidate = options['antidate']
|
|
|
+ date = options["date"]
|
|
|
+
|
|
|
try:
|
|
|
- date = datetime.datetime.strptime(args[0], '%Y-%m-%d').date()
|
|
|
+ date = datetime.datetime.strptime(date, '%Y-%m-%d').date()
|
|
|
except IndexError:
|
|
|
date = datetime.date.today()
|
|
|
except ValueError:
|
|
@@ -25,7 +53,7 @@ class Command(BaseCommand):
|
|
|
self.stdout.write(
|
|
|
'Create invoices for all members for the date : %s' % date)
|
|
|
with respect_language(settings.LANGUAGE_CODE):
|
|
|
- invoices = create_all_members_invoices_for_a_period(date)
|
|
|
+ invoices = create_all_members_invoices_for_a_period(date, antidate)
|
|
|
|
|
|
if len(invoices) > 0 or verbosity >= 2:
|
|
|
self.stdout.write(
|