Coverage for jacc/management/commands/update_invoices.py: 0%

# Coverage for jacc/management/commands/update_invoices.py : 0%

## 23 statements 0 run 23 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 from jacc.models import Invoice

2 from django.core.management.base import CommandParser

3 from jutil.command import SafeCommand

4

5

6 class Command(SafeCommand):

7 help = 'Updates cached values of invoices'

8

9 def add_arguments(self, parser: CommandParser):

10 parser.add_argument('--invoice', type=int)

11 parser.add_argument('--force', action='store_true')

12 parser.add_argument('--verbose', action='store_true')

13

14 def do(self, *args, **options):

15 invoices = Invoice.objects.all()

16 if options['invoice']:

17 invoices = invoices.filter(id=options['invoice'])

18 if not options['force']:

19 invoices = invoices.filter(close_date=None)

20

21 count = 0

22 for invoice in invoices.order_by('id'):

23 assert isinstance(invoice, Invoice)

24 if options['verbose']:

25 print('Updating', invoice)

26 invoice.update_cached_fields()

27 count += 1

28

29 print('Updated', count, 'invoices')