2024-04-23 21:31:05 +02:00
|
|
|
import datetime
|
2019-04-26 13:15:11 +02:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from django.conf import settings
|
2024-04-23 21:31:05 +02:00
|
|
|
from django.core.management.base import CommandError, CommandParser
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2019-04-26 13:15:11 +02:00
|
|
|
|
2024-04-23 21:30:37 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2019-04-26 13:15:11 +02:00
|
|
|
if settings.BILLING_ENABLED:
|
|
|
|
from corporate.lib.stripe import invoice_plans_as_needed
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-04-26 13:15:11 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
|
|
|
help = """Generates invoices for customers if needed."""
|
|
|
|
|
2024-04-23 21:31:05 +02:00
|
|
|
@override
|
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
|
|
|
if settings.DEVELOPMENT:
|
|
|
|
parser.add_argument("--date", type=datetime.datetime.fromisoformat)
|
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2024-04-23 21:30:37 +02:00
|
|
|
@abort_unless_locked
|
2019-04-26 13:15:11 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2024-04-23 21:31:05 +02:00
|
|
|
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)
|