Putting It Together: A High-Volume Invoicing System

Rather than repeating the management accounts we did in Word, we’ll discuss a different situation. Imagine that Pythonics is now doing a large volume of consulting work and needs to bill customers by the hour on a weekly basis. An internal database keeps track of who works for how many hours on which project. At the end of each week, we need to raise correct invoices and simultaneously enter them into our accounts system. Although starting small, we’d like a system that will scale up in the future.

We’ve built a tab-delimited text file called invoicing.dat that contains a list of the fields for each invoice; basically, the customer details, date, invoice number, number of hours worked, hourly rate, and so on. In a real application, this data might come from database queries, flat files, or already be available as an object model in memory. The script to generate the invoices is 200 lines long and is mostly graphics code; we’ll show some excerpts. First, the main loop:

def run():
    import os
    invoices = acquireData()   # parse the data file
    print 'loaded data'
    for invoice in invoices:
        printInvoice(invoice)
    print 'Done'

We’ll skip the data acquisition. Note also that in a real financial application, you’d extract transaction objects from your invoice objects and save them in a BookSet at the point of printing.

For each invoice, construct a PDFCanvas, call various drawing subroutines, and save it with an appropriate filename. In this case, ...

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.