Coverage for app/venv/lib/python3.14/site-packages/weblate/billing/management/commands/billing_check.py: 0%

31 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4from __future__ import annotations 

5 

6from typing import TYPE_CHECKING 

7 

8from weblate.billing.models import Billing 

9from weblate.billing.tasks import billing_notify 

10from weblate.utils.management.base import BaseCommand 

11 

12if TYPE_CHECKING: 

13 from django.core.management.base import CommandParser 

14 

15 

16class Command(BaseCommand): 

17 """Command for billing check.""" 

18 

19 help = "checks billing limits" 

20 

21 def add_arguments(self, parser: CommandParser) -> None: 

22 parser.add_argument("--valid", action="store_true", help="list valid ones") 

23 parser.add_argument( 

24 "--notify", action="store_true", help="send email notifications" 

25 ) 

26 

27 def handle(self, *args, **options) -> None: 

28 if options["notify"]: 

29 billing_notify() 

30 return 

31 Billing.objects.check_limits() 

32 if options["valid"]: 

33 for bill in Billing.objects.get_valid(): 

34 self.stdout.write(f" * {bill}") 

35 return 

36 limit = Billing.objects.get_out_of_limits() 

37 due = Billing.objects.get_unpaid() 

38 

39 if limit: 

40 self.stdout.write("Following billings are over limit:") 

41 for bill in limit: 

42 self.stdout.write(f" * {bill}") 

43 

44 if due: 

45 self.stdout.write("Following billings are past due date:") 

46 for bill in due: 

47 self.stdout.write(f" * {bill}")