Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Alex Vandiver67fcaf266ea5
diff --git a/zilencer/management/commands/invoice_plans.py b/zilencer/management/commands/invoice_plans.py
index 089b8261f2c..a45c421df1b 100644
--- a/zilencer/management/commands/invoice_plans.py
+++ b/zilencer/management/commands/invoice_plans.py
@@ -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)