Python for Small Business: Automate Your Invoicing
Manual invoicing wastes hours every month. Here is how to automate it with Python.
Generate PDF Invoices
from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvas from datetime import date
def generate_invoice ( client , items , invoice_num ): filename = " invoice_ " + str ( invoice_num ) + " .pdf " c = canvas . Canvas ( filename , pagesize = letter )
c . setFont ( " Helvetica-Bold " , 20 ) c . drawString ( 50 , 750 , " INVOICE " ) c . setFont ( " Helvetica " , 12 ) c . drawString ( 50 , 730 , " Invoice #: " + str ( invoice_num )) c . drawString ( 50 , 715 , " Date: " + str ( date . today ())) c . drawString ( 50 , 670 , " Bill To: " + client [ ' name ' ]) c . drawString ( 50 , 655 , client [ ' email ' ])
y = 600 total = 0 for item in items : amount = item [ ' qty ' ] * item [ ' rate ' ] total += amount c . drawString ( 50 , y , item [ ' description ' ]) c . drawString ( 400 , y , " $ " + str ( amount )) y -= 20
c .…