Hide keyboard shortcuts

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

1from jacc.models import Invoice 

2from django.core.management.base import CommandParser 

3from jutil.command import SafeCommand 

4 

5 

6class 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')