invoice_plans: Add a --date flag, rather than a commented line.

This commit is contained in:
Alex Vandiver
2024-04-23 19:31:05 +00:00
committed by Tim Abbott
parent e8e6abdbba
commit 67fcaf266e

View File

@@ -1,6 +1,8 @@
import datetime
from typing import Any
from django.conf import settings
from django.core.management.base import CommandError, CommandParser
from typing_extensions import override
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
@@ -12,11 +14,19 @@ if settings.BILLING_ENABLED:
class Command(ZulipBaseCommand):
help = """Generates invoices for customers if needed."""
@override
def add_arguments(self, parser: CommandParser) -> None:
if settings.DEVELOPMENT:
parser.add_argument("--date", type=datetime.datetime.fromisoformat)
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
if settings.BILLING_ENABLED:
# Uncomment to test with a specific date.
# from datetime import datetime, timezone
# date = datetime(2024, 5, 7, tzinfo=timezone.utc)
invoice_plans_as_needed()
if not settings.BILLING_ENABLED:
raise CommandError("Billing is not enabled!")
for_date = None
if settings.DEVELOPMENT and options["date"]:
for_date = options["date"].replace(tzinfo=datetime.timezone.utc)
invoice_plans_as_needed(for_date)