Storage and export - Keep books and transactions in SQLite (data/cashbook.db) instead of .ods files; existing .ods books are migrated once at startup - Export a book as the cashbook spreadsheet (.xlsx/.ods, built from the template via LibreOffice) or as CSV - GST rounded per transaction to match the spreadsheet Tax - GST return page with IRD GST101A boxes 5-15 per six-monthly, two-monthly or monthly period, due dates, and a Zero-rated GST type - Income tax page with IR10 (financial statements summary) and IR4 (company return) boxes, from the cashbook plus year-end amounts typed in and saved per book FastAPI and accounts (following led-editor) - Replace the stdlib server with a FastAPI app (src/cashbook_app) run by uvicorn; dependencies in Pipfile - Cookie sessions with bcrypt passwords, first-run admin setup or BOOTSTRAP_ADMIN_*, invites (link or email), sign-in throttling, password change that signs out other sessions - Users page for administrators: rename, reset password, promote or demote, delete, list and revoke invites; last admin is protected - Replaces the shared CASHBOOK_PASSWORD basic auth; AUTH_* settings in .env (see .env.example) - Docker image uses a venv with system site packages for python3-uno - pytest suite for auth, user management, imports, GST and tax figures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
3.1 KiB
Python
63 lines
3.1 KiB
Python
from conftest import SAMPLE_CSV
|
|
|
|
|
|
def setup_book(admin):
|
|
admin.post("/api/books", json={"name": "b", "year": 2026, "opening_balance": "100"})
|
|
path = admin.post("/api/upload?filename=april.csv", content=SAMPLE_CSV.encode()).json()["path"]
|
|
admin.post("/api/import", json={"book": "b", "statements": [path]})
|
|
rows = admin.get("/api/month?book=b&sheet=APR").json()["rows"]
|
|
sale = next(r for r in rows if r["income"] == 1150)
|
|
jaycar = next(r for r in rows if r["expense"] == 115)
|
|
admin.post("/api/row", json={"book": "b", "sheet": "APR", "row": sale["row"], "gst": "Incl GST", "category": "Sales"})
|
|
admin.post("/api/row", json={"book": "b", "sheet": "APR", "row": jaycar["row"], "category": "Purchases"})
|
|
|
|
|
|
def values(data, form):
|
|
return {r["box"]: r["value"] for r in data[form.lower()]["rows"] if r["box"]}
|
|
|
|
|
|
def test_ir10_from_cashbook(admin):
|
|
setup_book(admin)
|
|
data = admin.get("/api/tax?book=b").json()
|
|
v = values(data, "IR10")
|
|
assert v["2"] == 1000.0 # sales excluding GST
|
|
assert v["4"] == 100.0 # purchases excluding GST
|
|
assert v["6"] == 900.0
|
|
assert v["24"] == 8.5 # bank fees
|
|
assert v["27"] == 891.5
|
|
assert v["31"] == round(100 - 8.5 - 115 + 1150 + 500 - 5.53, 2) # bank balance at year end
|
|
assert v["57"] == 0.0
|
|
assert any("isn't allocated" in n for n in data["ir10"]["notes"]) # the Hetzner payment
|
|
assert any("funds introduced" in n for n in data["ir10"]["notes"])
|
|
|
|
|
|
def test_adjustments_and_ir4(admin):
|
|
setup_book(admin)
|
|
# depreciation, closing stock and RWT; tax to pay at 28%
|
|
admin.post("/api/tax", json={"book": "b", "form": "IR10", "box": "13", "value": 91.5})
|
|
admin.post("/api/tax", json={"book": "b", "form": "IR10", "box": "5", "value": 50})
|
|
data = admin.post("/api/tax", json={"book": "b", "form": "IR4", "box": "30K", "value": 100}).json()
|
|
v10, v4 = values(data, "IR10"), values(data, "IR4")
|
|
assert (v10["6"], v10["25"], v10["29"]) == (950.0, 100.0, 850.0)
|
|
assert (v4["20B"], v4["29"], v4["30A"], v4["30B"]) == (850.0, 850.0, 850.0, 238.0)
|
|
assert v4["30L"] == 138.0
|
|
assert data["ir4"]["result"] == {"amount": 138.0, "kind": "to pay"}
|
|
|
|
# adjustments add to the cashbook figure, and clearing one removes it
|
|
data = admin.post("/api/tax", json={"book": "b", "form": "IR10", "box": "2", "value": -1000}).json()
|
|
assert values(data, "IR10")["2"] == 0.0
|
|
assert data["ir4"]["result"]["kind"] == "refund" # a loss: no tax, provisional tax comes back
|
|
data = admin.post("/api/tax", json={"book": "b", "form": "IR10", "box": "2", "value": None}).json()
|
|
assert values(data, "IR10")["2"] == 1000.0
|
|
|
|
|
|
def test_tax_inputs_are_checked(admin):
|
|
setup_book(admin)
|
|
assert admin.post("/api/tax", json={"book": "b", "form": "IR10", "box": "29", "value": 1}).status_code == 400
|
|
assert admin.post("/api/tax", json={"book": "b", "form": "IR3", "box": "1", "value": 1}).status_code == 400
|
|
assert admin.get("/api/tax?book=nope").status_code == 404
|
|
|
|
|
|
def test_tax_needs_sign_in(client):
|
|
assert client.get("/api/tax?book=b").status_code == 401
|