Move to FastAPI with accounts, SQLite books, export and tax returns
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>
This commit is contained in:
1 parent
17b48f25e8
commit
4b3e5f0932
47 files changed
+4189
-862
No files matched your search
+10
-27
@@ -1,24 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Create a new cashbook for a financial year by copying src/template.ods.
|
||||
|
||||
Sets the starting year (April) and, optionally, the opening bank balance on
|
||||
the 'Summary report' sheet so the month sheets pick them up.
|
||||
"""Create a new cashbook (in the database) for a financial year, April to March.
|
||||
|
||||
Usage:
|
||||
new_book.py OUT.ods [--year 2025] [--opening-balance 1234.56]
|
||||
new_book.py NAME [--year 2025] [--opening-balance 1234.56] [--data DIR]
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from datetime import date
|
||||
|
||||
from cashbook import setup_book
|
||||
from office import open_book
|
||||
import ledger
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.path.dirname(HERE)
|
||||
TEMPLATE = os.path.join(HERE, "template.ods")
|
||||
|
||||
|
||||
def current_fy_start():
|
||||
@@ -26,33 +20,22 @@ def current_fy_start():
|
||||
return today.year if today.month >= 4 else today.year - 1
|
||||
|
||||
|
||||
def create_book(out, year, opening_balance=None, open_fn=open_book, template=TEMPLATE):
|
||||
if os.path.exists(out):
|
||||
raise FileExistsError(f"{out} already exists")
|
||||
shutil.copy2(template, out)
|
||||
try:
|
||||
with open_fn(out) as doc:
|
||||
setup_book(doc, year, opening_balance)
|
||||
doc.store()
|
||||
except Exception:
|
||||
os.remove(out)
|
||||
raise
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
||||
ap.add_argument("out", help="new cashbook .ods to create")
|
||||
ap.add_argument("name", help="name for the book, e.g. cashbook-2025-26")
|
||||
ap.add_argument("--year", type=int, default=current_fy_start(),
|
||||
help="calendar year the financial year starts in (default: current)")
|
||||
ap.add_argument("--opening-balance", type=float,
|
||||
ap.add_argument("--opening-balance", type=float, default=0.0,
|
||||
help="bank balance at 1 April (default: 0)")
|
||||
ap.add_argument("--data", default=os.path.join(ROOT, "data"))
|
||||
args = ap.parse_args()
|
||||
|
||||
conn = ledger.connect(os.path.join(args.data, "cashbook.db"))
|
||||
try:
|
||||
create_book(args.out, args.year, args.opening_balance)
|
||||
except FileExistsError as e:
|
||||
ledger.create_book(conn, args.name, args.year, args.opening_balance)
|
||||
except ValueError as e:
|
||||
sys.exit(str(e))
|
||||
print(f"Created {args.out} for April {args.year} - March {args.year + 1}")
|
||||
print(f"Created {args.name} for April {args.year} - March {args.year + 1}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user