Add cashbook web app for importing ANZ statements
Local web app and CLI that fill a NZ cashbook spreadsheet (one sheet per month, April-March) from ANZ CSV exports and PDF statements, via a headless LibreOffice. - Import with preview; duplicates matched on date and amount so CSV and PDF versions of the same period don't double up - Statement upload (drag and drop), view, download, rename and remove, with per-book import status - Month review with GST and category editing, year summary and six-monthly GST returns - Docker Compose setup; books and statements live in data/ (ignored) - Blank cashbook template (NZ Government, CC BY 4.0); code under AGPL-3.0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
971de14356
15 files changed
+2520
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#!/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.
|
||||
|
||||
Usage:
|
||||
new_book.py OUT.ods [--year 2025] [--opening-balance 1234.56]
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from datetime import date
|
||||
|
||||
from cashbook import setup_book
|
||||
from office import open_book
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.path.dirname(HERE)
|
||||
TEMPLATE = os.path.join(HERE, "template.ods")
|
||||
|
||||
|
||||
def current_fy_start():
|
||||
today = date.today()
|
||||
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("--year", type=int, default=current_fy_start(),
|
||||
help="calendar year the financial year starts in (default: current)")
|
||||
ap.add_argument("--opening-balance", type=float,
|
||||
help="bank balance at 1 April (default: 0)")
|
||||
args = ap.parse_args()
|
||||
|
||||
try:
|
||||
create_book(args.out, args.year, args.opening_balance)
|
||||
except FileExistsError as e:
|
||||
sys.exit(str(e))
|
||||
print(f"Created {args.out} for April {args.year} - March {args.year + 1}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user