Phase 2: core domain, policy engine, packet API, Clerical screen

Migration 0003: projects, aliases, renumbers, units, packets and every child table,
change orders, assets, documents, ITPs, station limits, department weld flag.
Policy package: Principal, PacketState, Action rules, custody, preconditions,
CO hold, order of checks, can/blocked/holder on reads. docs/POLICY.md with the
tightenings table for Seth. Write pipeline: FOR UPDATE, CAS on status and dept,
If-Match row versions, server-assigned numbers, field CAS, version bump, packet
log, audit, NOTIFY, signatures, IT reasons, filed lock and HMAC seal.
API: /api/packets (header, transitions, work orders, pages, docs, move, remove,
BOM, shorts, welds, heat tags, heat table, stage, checklist, clock, warehouse
stage, Q.C., change orders, log, seal), /api/projects, /api/units, /api/assets,
/_blob. Frontend: Clerical home, projects and units, packet page with pdf.js
and QR codes, hand draft, heat map, send to warehouse, department or Q.C.
Tests: policy matrix, API, concurrency, schema, projects; Playwright Clerical
draft scenario. Verified on docker-1 with the CI stack and the Samba DC.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
2026-10-16 09:31:45 -06:00
co-authored by Claude Fable 5.1
parent 97b0973130
commit 37d9a0cb50
83 changed files with 16490 additions and 55 deletions
+9 -6
View File
@@ -15,12 +15,15 @@ router = APIRouter(prefix="/api", tags=["departments"])
def departments(_: Principal = Depends(current_principal), d: Db = Depends(get_db)) -> list[dict[str, Any]]: # noqa: B008
conn = d.conn
rows = conn.execute(
"SELECT code, slug, name, kind::text FROM departments WHERE active ORDER BY sort, code"
"SELECT code, slug, name, kind::text, weld FROM departments WHERE active ORDER BY sort, code"
).fetchall()
stations = conn.execute(
"SELECT dept_code, name FROM stations WHERE active ORDER BY dept_code, sort, name"
"SELECT dept_code, id, name FROM stations WHERE active ORDER BY dept_code, sort, name"
).fetchall()
by_dept: dict[str, list[str]] = {}
for code, name in stations:
by_dept.setdefault(code, []).append(name)
return [{"code": r[0], "slug": r[1], "name": r[2], "kind": r[3], "stations": by_dept.get(r[0], [])} for r in rows]
by_dept: dict[str, list[dict[str, Any]]] = {}
for code, sid, name in stations:
by_dept.setdefault(code, []).append({"id": int(sid), "name": name})
return [
{"code": r[0], "slug": r[1], "name": r[2], "kind": r[3], "weld": bool(r[4]), "stations": by_dept.get(r[0], [])}
for r in rows
]