How to write a correct freelance invoice: the math, the numbering, and a small offline app

2026-11-28来源 dev.toEnglish

Most freelancers do not need a $20 per month invoicing app. They need an invoice with the right number, the right math and a PDF. Here is what a good invoice must contain, and a small free Python snippet that does the math correctly.

Disclosure: I sell a packaged version of this idea (link at the end). The snippet below is free to copy and use.

What every invoice needs

  1. Your name and contact details, and the client's
  2. A unique, sequential invoice number (accountants and tax offices expect no gaps)
  3. Issue date and due date
  4. Line items with quantity, unit price and amount
  5. Subtotal, tax, discount and total, clearly separated
  6. Payment terms, such as "due within 14 days"
  7. A status you can track: unpaid, paid, overdue

The math, done safely

Never use floats for money. Use Decimal and round once per line.

from decimal import Decimal, ROUND_HALF_UP def money(x): return Decimal(x).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP) items = [("Website design", 1, "1200.00"), ("Hosting setup", 2, "75.00")] subtotal = sum(money(Decimal(q) * Decimal(p)) for _, q, p in items) discount = money(subtotal * Decimal("0.05")) tax = money((subtotal - discount) * Decimal("0.00")) total = subtotal - discount + tax print(subtotal, discount, tax, total) # 1350.00 67.50 0.00 1282.50 

Numbering

Keep a counter in a small file and increment it only after you save the invoice. Print it as INV-0001. If you delete an invoice, void it instead so the number sequence stays intact.

Print to PDF without any library

Generate a plain HTML invoice with a print stylesheet and use your browser's "Save as PDF". It looks the same on every machine and needs no dependency.

Free template

If you just want a clean invoice layout to start from, there is a free one here (no payment needed): https://qwfjdwhi.gumroad.com/l/guylvw?utm_source=devto&utm_medium=article&utm_campaign=freeinvoice

If you want it ready to use

I packaged this into InvoiceKit 2: a point-and-click invoice maker that opens in your browser and runs only on your computer. It has automatic numbers, tax and discount, a paid and unpaid list with totals, and double-click starters for Windows, Mac and Linux. It needs free Python 3. It does not send emails or take online payments.

$19, one time: https://qwfjdwhi.gumroad.com/l/hjhqxw?utm_source=devto&utm_medium=article&utm_campaign=invoicekit

Launch offer until 2 Dec 2026: InvoiceKit 2, an Excel profit tracker and a landing page template together for $10 (they cost $53 separately): https://qwfjdwhi.gumroad.com/l/ntnra?utm_source=devto&utm_medium=article&utm_campaign=launch10

What do you wish your invoices did automatically? I read the comments.

原文:https://www.a8q9.cn/en/article/how-to-write-a-correct-freelance-invoice-the-math-the-numbering-and-a-small-offl-3af533.html

相关文章