import repository from arizona
[raven.git] / apps / gacks / dumpInvoice.py
1 import time
2
3 from gacksaccount import GacksAccount
4 from gacksaccountmanager import GacksAccountManager
5 from gacksinvoice import *
6
7 class InvoiceDumper:
8     def __init__(self, tableName="gacksinvoice"):
9         self.accounts = GacksAccountManager()
10         self.invoices = GacksInvoiceManager(tableName=tableName, accounts=self.accounts)
11
12     def dump_invoice(self, name):
13         account = self.accounts.get_account(name, "user")
14
15         print "account:", account.name
16         print "balance:", account.balance
17
18         pending_invoice = self.invoices.get_invoice(name, STATE_PENDING)
19         applied_invoice = self.invoices.get_invoice(name, STATE_APPLIED)
20         charged_invoice = self.invoices.get_invoice(name, STATE_INVOICED)
21
22         all_charges = pending_invoice.charges + applied_invoice.charges + charged_invoice.charges
23
24         all_charges = sorted(all_charges, key=lambda charge: charge.date)
25
26         for charge in all_charges:
27             print "%5d %5d %24s %-32s %5.0f" % (int(charge.id), int(charge.parent_id), time.ctime(charge.date), self.invoices.get_object_name(charge.object_id), float(charge.amount))
28
29 def main():
30     if len(sys.argv)<2:
31         print "syntax: dumpInvoice.py <accountname>"
32         return
33
34     dumper=InvoiceDumper() # ("gacksinvoice_test")
35     dumper.dump_invoice(sys.argv[1])
36
37 if __name__=="__main__":
38     main()
39