import json, csv from decimal import Decimal as D inv = json.load(open("output/invoices.json")) po = list(csv.DictReader(open("inputs/purchase-orders.csv"))) for r in inv: sub = sum(D(str(l["qty"])) * D(str(l["unit_price"])) for l in r["line_items"]) tax = (sub * D("0.12")).quantize(D("0.01")) tot = sub + tax + D(str(r["shipping"])) print(r["invoice_number"], "calc sub", sub, "tax", tax, "total", tot, "stated", r["total"], "match", tot == D(str(r["total"]))) for l in r["line_items"]: p = [x for x in po if x["po"] == r["po"] and x["item"] == l["description"]][0] print(" ", l["description"], "qty", l["qty"], "po", p["qty"], "unit", l["unit_price"], "po", p["unit_cad"], "bank inv", r["bank_account_suffix"], "po", p["bank_suffix"]) psub = sum(D(x["qty"]) * D(x["unit_cad"]) for x in po if x["po"] == r["po"]) print(" PO expected", psub, (psub*D("0.12")).quantize(D("0.01"))) n = len(open("output/review-note.md").read().split()) print("note words", n)