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 decimal import Decimal 

2from django.core.management.base import CommandParser 

3from jacc.models import AccountEntry, Invoice 

4from jutil.command import SafeCommand 

5 

6 

7class Command(SafeCommand): 

8 help = 'Invoice balance' 

9 

10 def add_arguments(self, parser: CommandParser): 

11 parser.add_argument('invoice', type=int) 

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

13 

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

15 inv = Invoice.objects.get(id=options['invoice']) 

16 assert isinstance(inv, Invoice) 

17 inv.update_cached_fields() 

18 

19 print('Invoice id={} balances:'.format(inv.id)) 

20 for item, bal in inv.get_item_balances(inv.receivables_account): 

21 assert isinstance(item, AccountEntry) 

22 assert isinstance(bal, Decimal) 

23 print(' {} balance {}'.format(item, bal)) 

24 

25 if options['tx']: 

26 bal = Decimal('0.00') 

27 for tx in inv.receivables.order_by('timestamp', 'id'): 

28 assert isinstance(tx, AccountEntry) 

29 bal += tx.amount 

30 print(' [{}] {} {} {}{} {}'.format(tx.id, tx.timestamp.date().isoformat(), tx.type, 

31 '+' if tx.amount >= Decimal('0.00') else '', tx.amount, bal))