O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required