Phase 7: close, file, PDFs and prints
Clerical close and file: the VISUAL observed state beside the close confirm, a 409 with a second confirm when the feed still shows work orders open, filing with a signature and the HMAC seal, the data book built on the server and stored on the seal in the filing transaction, admin reopen keeping the broken seal with its data book. Server PDFs with reportlab, pypdf and pypdfium2: the manufacturing data book page for page after the old build (cover, index, drawings with VOID stamps, traceability and heat map rasters, weld maps and welding records, Q.C. inspections, Q.C. and test documents, MTRs, record history), the job traveler with work order QR codes, the ITP PDF filed automatically at sign-off, every print kind with the PRINTED COPY stamp, the controlled-copy stamp signed with the seal key, PDF metadata, the traceability CSV with the formula guard, and the append-only print_log with an audit row for every print and export (migration 0008). Frontend: the close and file panel, the print menu and its entry points, the printed copies list on the History tab, the ITP PDF buttons. Tests: server (close, file, reopen, seal, the builders, prints, CSV, stamps), frontend, and the Playwright close and print scenarios. Docs updated; SECURITY closes M2, S6, S7 and S8. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
"""The heat map and the weld map of one drawing page, as a JPEG at the sheet's own size (the old renderMapCanvas)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from ..domain import assets
|
||||
from . import raster
|
||||
from .style import fmt_d, site_tz
|
||||
|
||||
|
||||
def asset_file(conn: Any, settings: Any, asset_id: Any) -> tuple[dict[str, Any], Path]:
|
||||
"""The assets row and its stored file. Raises when the row or the file is missing."""
|
||||
row = assets.get(conn, asset_id) if asset_id else None
|
||||
if row is None:
|
||||
raise FileNotFoundError("The file is not in the asset store.")
|
||||
return row, assets.open_blob(settings, row)
|
||||
|
||||
|
||||
def page_file(conn: Any, settings: Any, page: Mapping[str, Any]) -> tuple[Path, int]:
|
||||
"""The stored PDF of a packet page and the page number inside it."""
|
||||
_row, path = asset_file(conn, settings, page.get("asset_id"))
|
||||
return path, int(page.get("pn") or 1)
|
||||
|
||||
|
||||
def void_text(page: Mapping[str, Any], tz: str | None = None) -> str:
|
||||
"""VOID - superseded by CO-2 (dwg Rev B) 10/16/2026. Empty for a live page (the old voidText)."""
|
||||
v = page.get("void")
|
||||
if not v:
|
||||
return ""
|
||||
co = f"CO-{v['co_no']}" if v.get("co_no") is not None else "a change order"
|
||||
new = v.get("new")
|
||||
sheet = f" ({new.get('dwg') or 'new sheet'} Rev {new.get('rev') or '?'})" if new else ""
|
||||
day = fmt_d(v.get("at"), tz, empty="")
|
||||
return f"VOID - superseded by {co}{sheet}" + (f" {day}" if day else "")
|
||||
|
||||
|
||||
def heat_placement(packet: Mapping[str, Any], page_n: int) -> Mapping[str, Any] | None:
|
||||
"""The heat table placed on a page, or None."""
|
||||
for h in packet.get("heat_table") or []:
|
||||
if h.get("page") == page_n and h.get("x") is not None:
|
||||
return h
|
||||
return None
|
||||
|
||||
|
||||
def legacy_tags(packet: Mapping[str, Any], page_n: int) -> list[Mapping[str, Any]]:
|
||||
"""The older heat tags of a page. They show only while no table is placed on it."""
|
||||
if heat_placement(packet, page_n) is not None:
|
||||
return []
|
||||
return [t for t in packet.get("heat_tags") or [] if t.get("page") == page_n]
|
||||
|
||||
|
||||
def page_welds(packet: Mapping[str, Any], page_n: int) -> list[Mapping[str, Any]]:
|
||||
return [w for w in packet.get("welds") or [] if w.get("page") == page_n]
|
||||
|
||||
|
||||
def _render(conn: Any, settings: Any, page: Mapping[str, Any]) -> tuple[Any, float, float]:
|
||||
path, pn = page_file(conn, settings, page)
|
||||
return raster.render_page(path, pn)
|
||||
|
||||
|
||||
def heat_map_page(
|
||||
conn: Any, settings: Any, packet: Mapping[str, Any], page: Mapping[str, Any]
|
||||
) -> tuple[bytes, float, float]:
|
||||
"""The sheet with its heat table (or its older heat tags when no table is placed), VOID when the page is void.
|
||||
Returns (jpeg bytes, width pt, height pt)."""
|
||||
img, w, h = _render(conn, settings, page)
|
||||
n = int(page["n"])
|
||||
bom = packet.get("bom") or []
|
||||
placement = heat_placement(packet, n)
|
||||
if placement is not None:
|
||||
raster.draw_heat_table(img, placement, raster.heat_rows(bom))
|
||||
else:
|
||||
raster.draw_heat_tags(img, packet.get("heat_tags") or [], bom, n)
|
||||
if page.get("void"):
|
||||
img = raster.stamp_void(img, void_text(page, site_tz(settings)))
|
||||
return raster.to_jpeg(img), w, h
|
||||
|
||||
|
||||
def weld_map_page(
|
||||
conn: Any, settings: Any, packet: Mapping[str, Any], page: Mapping[str, Any]
|
||||
) -> tuple[bytes, float, float]:
|
||||
"""The sheet with its weld bubbles, VOID when the page is void. Returns (jpeg bytes, width pt, height pt)."""
|
||||
img, w, h = _render(conn, settings, page)
|
||||
raster.draw_weld_marks(img, packet.get("welds") or [], int(page["n"]))
|
||||
if page.get("void"):
|
||||
img = raster.stamp_void(img, void_text(page, site_tz(settings)))
|
||||
return raster.to_jpeg(img), w, h
|
||||
|
||||
|
||||
def clean_page(conn: Any, settings: Any, page: Mapping[str, Any]) -> tuple[bytes, float, float]:
|
||||
"""The sheet with no marks (VOID when void), as a raster. Prints copy the vector page instead; this is for a
|
||||
page whose PDF cannot be copied."""
|
||||
img, w, h = _render(conn, settings, page)
|
||||
if page.get("void"):
|
||||
img = raster.stamp_void(img, void_text(page, site_tz(settings)))
|
||||
return raster.to_jpeg(img), w, h
|
||||
Reference in New Issue
Block a user