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,78 @@
|
||||
"""Phase 7 job traveler builder: the page count, the work order boxes (the QR text is a barcode, never text; the
|
||||
work order, lot and seq are text), the blanks for a packet with no heats, the sign-off rows after signed steps, the
|
||||
note for a packet with no work orders, the stamp and the metadata."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from closehelpers import at_complete, builder_conn, flat, page_texts, pdf_reader, who
|
||||
from fakedir import FakeDirectory
|
||||
from pkthelpers import make_draft
|
||||
from pshelpers import needs_pg
|
||||
from shophelpers import BOM3, WOS, Shop, draft, make_unit, open_shop
|
||||
|
||||
from packetstation.pdf import traveler
|
||||
from packetstation.settings import Settings
|
||||
|
||||
pytestmark = needs_pg
|
||||
|
||||
NOW = datetime(2026, 10, 17, 21, 4, tzinfo=UTC)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def shop(pg_settings: Settings, fake_dir: FakeDirectory, dev_visual: None) -> Iterator[Shop]:
|
||||
yield from open_shop(pg_settings, fake_dir)
|
||||
|
||||
|
||||
def build(shop: Shop, pid: int) -> Any:
|
||||
with builder_conn(shop.settings) as conn:
|
||||
return traveler.build(conn, shop.settings, pid, who=who(shop), now=NOW)
|
||||
|
||||
|
||||
def test_traveler_of_a_draft(shop: Shop) -> None:
|
||||
"""A draft with no signed step yet (no drawing attached, so no signed attach row): the blank sign-off rows."""
|
||||
_, unit_id = make_unit(shop.settings)
|
||||
pkt = make_draft(shop("clerk.clara"), unit_id, bom=BOM3, work_orders=WOS)
|
||||
built = build(shop, pkt["id"])
|
||||
assert built.bytes[:5] == b"%PDF-"
|
||||
reader = pdf_reader(built.bytes)
|
||||
assert len(reader.pages) == built.pages >= 1
|
||||
texts = page_texts(built.bytes)
|
||||
text = flat(" ".join(texts))
|
||||
assert "JOB TRAVELER" in text.upper()
|
||||
for wo in ("L670001", "L670002"):
|
||||
assert wo in text
|
||||
assert "Lot 001" in text and "Seq" in text
|
||||
# the QR payload is drawn as a barcode, never as text
|
||||
assert "*%2" not in text and "$001$0$0$" not in text
|
||||
# no heats yet: blanks
|
||||
assert "________" in text
|
||||
assert "Work complete (stall)" in text and "Supervisor review" in text and "Q.C. inspection" in text
|
||||
project = pkt["unit"]["project"]["number"]
|
||||
for i, t in enumerate(texts):
|
||||
ft = flat(t)
|
||||
assert "Controlled copy - exported by Clara Clerk (4001)" in ft, i
|
||||
assert f"Page {i + 1} of {len(texts)}" in ft, i
|
||||
assert reader.metadata.title == f"{project} Lot 001 Job Traveler", reader.metadata.title
|
||||
assert reader.metadata.producer == "Packet Station"
|
||||
|
||||
|
||||
def test_traveler_after_signed_steps(shop: Shop) -> None:
|
||||
pkt = at_complete(shop)
|
||||
text = flat(" ".join(page_texts(build(shop, pkt["id"]).bytes)))
|
||||
assert "Andy Welder (3003)" in text # signed the submit
|
||||
assert "Wes Super (2003)" in text # signed the send to Q.C.
|
||||
assert "Quinn QC (5001)" in text # signed the accept
|
||||
assert "Work complete (stall)" not in text
|
||||
assert "HT-10" in text # the heats pulled in the warehouse
|
||||
assert "Q.C. ACCEPTED" in text
|
||||
|
||||
|
||||
def test_traveler_without_work_orders(shop: Shop) -> None:
|
||||
pkt = draft(shop, wos=[])
|
||||
text = flat(" ".join(page_texts(build(shop, pkt["id"]).bytes)))
|
||||
assert "No work orders were read from this packet." in text
|
||||
Reference in New Issue
Block a user