Add production order search and shift drill-down
This commit is contained in:
1 parent
6e8eb6f50f
commit
dcde029bc7
8 files changed
+742
-4
No files matched your search
@@ -0,0 +1,114 @@
|
||||
"""Server-rendered, escaped production-order search and detail pages."""
|
||||
|
||||
from html import escape
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from production_analytics.service.production_order import (
|
||||
ProductionOrderDetail,
|
||||
ProductionOrderSearchResult,
|
||||
)
|
||||
|
||||
SHIFT_LABELS = {"early": "Frühschicht", "late": "Spätschicht", "night": "Nachtschicht"}
|
||||
|
||||
|
||||
def _page(title: str, body: str) -> str:
|
||||
return f'''<!doctype html><html lang="de"><head><meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{escape(title)}</title><style>
|
||||
body {{font:16px system-ui,sans-serif;background:#f4f6f8;color:#182c3b;margin:0}}
|
||||
main {{max-width:1100px;margin:2rem auto;padding:1.5rem;background:white}}
|
||||
form {{display:flex;flex-wrap:wrap;gap:.7rem;align-items:end;padding:1rem;background:#e8eef3}}
|
||||
label {{display:grid;gap:.4rem}} input,button {{font:inherit;padding:.55rem}}
|
||||
table {{width:100%;border-collapse:collapse}} th,td {{text-align:left;padding:.7rem;
|
||||
border-bottom:1px solid #c9d1d8}} th {{background:#e8eef3}}
|
||||
.table-scroll {{overflow-x:auto}} .metadata {{color:#526473;font-size:.9rem}}
|
||||
.error {{padding:1rem;background:#ffe8e5;border-left:4px solid #a32920}}
|
||||
</style></head><body><main><nav><a href="/">Schichtberichte</a> ·
|
||||
<a href="/orders">Fertigungsauftrag suchen</a></nav>{body}</main></body></html>'''
|
||||
|
||||
|
||||
def _form(query: str) -> str:
|
||||
return ('<form method="get" action="/orders"><label>Fertigungsauftrag (FA)'
|
||||
f'<input type="search" name="q" value="{escape(query, quote=True)}"'
|
||||
' maxlength="80" required></label><button type="submit">Suchen</button></form>')
|
||||
|
||||
|
||||
def _text(value: str | None) -> str:
|
||||
return escape(value) if value else "–"
|
||||
|
||||
|
||||
def _period(value, timezone) -> str:
|
||||
label = value.strftime("%d.%m.%Y %H:%M")
|
||||
return escape(f"{label} ({timezone.key})" if timezone else f"{label} (ERP-Lokalzeit)")
|
||||
|
||||
|
||||
def render_search(*, query: str = "", results: tuple[ProductionOrderSearchResult, ...] = (),
|
||||
error: str | None = None, searched: bool = False) -> str:
|
||||
body = "<h1>Fertigungsauftrag suchen</h1>" + _form(query)
|
||||
if error:
|
||||
body += f'<p class="error" role="alert">{escape(error)}</p>'
|
||||
elif searched:
|
||||
if not results:
|
||||
body += "<p>Keine passenden Fertigungsaufträge gefunden.</p>"
|
||||
else:
|
||||
body += '<div class="table-scroll"><table><thead><tr><th>FA</th><th>Artikel</th>'
|
||||
body += '<th>Artikelbezeichnung</th><th>Arbeitsplatz / Maschine</th>'
|
||||
body += '<th>Erste Rückmeldung</th><th>Letzte Rückmeldung</th></tr></thead><tbody>'
|
||||
for result in results:
|
||||
href = "/order?" + urlencode({"production_order": result.production_order})
|
||||
for placement in result.placements:
|
||||
machine = placement.machine_name or "nicht zugeordnet"
|
||||
link = (f'<a href="{escape(href, quote=True)}">'
|
||||
f'{escape(result.production_order)}</a>')
|
||||
body += "<tr>" + "".join(f"<td>{cell}</td>" for cell in (
|
||||
link,
|
||||
_text(placement.article_number), _text(placement.article_description),
|
||||
escape(f"{placement.workplace} / {machine}"),
|
||||
_period(placement.first_confirmation_local, placement.timezone),
|
||||
_period(placement.last_confirmation_local, placement.timezone),
|
||||
)) + "</tr>"
|
||||
body += "</tbody></table></div>"
|
||||
return _page("Fertigungsauftrag suchen", body)
|
||||
|
||||
|
||||
def render_detail(*, detail: ProductionOrderDetail | None,
|
||||
error: str | None = None) -> str:
|
||||
if error:
|
||||
return _page("Fertigungsauftrag", f'<p class="error" role="alert">{escape(error)}</p>')
|
||||
if detail is None:
|
||||
return _page("Fertigungsauftrag", "<p>Fertigungsauftrag nicht gefunden.</p>")
|
||||
body = f"<h1>Fertigungsauftrag {escape(detail.production_order)}</h1>"
|
||||
body += '<p class="metadata">Zeiten sind ERP-Rückmeldezeitpunkte, keine durchgehenden '
|
||||
body += 'Maschinenlaufzeiten. Mengen sind positive Rückmeldemengen in m².</p>'
|
||||
body += '<h2>Artikel und Arbeitsplätze</h2><div class="table-scroll"><table><thead><tr>'
|
||||
body += '<th>Artikel</th><th>Artikelbezeichnung</th><th>Arbeitsplatz / Maschine</th>'
|
||||
body += '<th>Erste Rückmeldung</th><th>Letzte Rückmeldung</th></tr></thead><tbody>'
|
||||
for placement in detail.placements:
|
||||
machine = placement.machine_name or f"nicht zugeordnet ({placement.mapping_status})"
|
||||
body += "<tr>" + "".join(f"<td>{cell}</td>" for cell in (
|
||||
_text(placement.article_number), _text(placement.article_description),
|
||||
escape(f"{placement.workplace} / {machine}"),
|
||||
_period(placement.first_confirmation_local, placement.timezone),
|
||||
_period(placement.last_confirmation_local, placement.timezone),
|
||||
)) + "</tr>"
|
||||
body += '</tbody></table></div><h2>Schichten</h2>'
|
||||
if not detail.shifts:
|
||||
body += "<p>Keine Schichtzuordnung für konfigurierte Maschinen verfügbar.</p>"
|
||||
else:
|
||||
body += '<div class="table-scroll"><table><thead><tr><th>Standort</th><th>Maschine</th>'
|
||||
body += '<th>Datum</th><th>Schicht</th><th>Produzierte Menge</th>'
|
||||
body += '<th>Erste Rückmeldung</th><th>Letzte Rückmeldung</th><th>Bericht</th>'
|
||||
body += '</tr></thead><tbody>'
|
||||
for item in detail.shifts:
|
||||
href = "/?" + urlencode({"date": item.date.isoformat(), "shift": item.shift,
|
||||
"machine": item.machine_name})
|
||||
body += "<tr>" + "".join(f"<td>{cell}</td>" for cell in (
|
||||
escape(item.site.title()), escape(item.machine_name),
|
||||
item.date.strftime("%d.%m.%Y"),
|
||||
SHIFT_LABELS[item.shift], f"{item.produced_m2:,.2f} m²",
|
||||
escape(item.first_confirmation.strftime("%d.%m.%Y %H:%M %Z")),
|
||||
escape(item.last_confirmation.strftime("%d.%m.%Y %H:%M %Z")),
|
||||
f'<a href="{escape(href, quote=True)}">Schichtbericht</a>',
|
||||
)) + "</tr>"
|
||||
body += "</tbody></table></div>"
|
||||
return _page(f"Fertigungsauftrag {detail.production_order}", body)
|
||||
@@ -117,7 +117,8 @@ width:220px; max-width:100%; margin:.75rem auto}}
|
||||
.material-swatch {{width:.9rem; height:.9rem; flex-shrink:0; margin-top:.2rem}}
|
||||
@media(max-width:850px) {{.material-layout {{grid-template-columns:minmax(0, 1fr)}}}}
|
||||
.error {{padding:1rem; background:#ffe8e5; border-left:4px solid #a32920}}
|
||||
</style></head><body><main><h1>Live-Schichtberichte</h1>
|
||||
</style></head><body><main><nav><a href="/orders">Fertigungsauftrag suchen</a></nav>
|
||||
<h1>Live-Schichtberichte</h1>
|
||||
<form method="get" action="/">
|
||||
<label>Datum (Schichtbeginn)<input type="date" name="date" required
|
||||
value="{day.isoformat()}"></label>
|
||||
|
||||
Reference in new issue
Block a user