Web: QR-Etiketten-Export (CSV für P-touch & Co.)
Auf "Import / Export" neue Karte: Kategorien auswaehlen (inkl. Unterkategorien) und je Einzelstueck eine CSV-Zeile herunterladen - Spalten QR-Inhalt (…/i/<UID>), UID, Produkt, Marke, Kategorie, Lagerort. In der Etiketten-Software als Datenbank verknuepfen, dann entsteht QR + Text automatisch - kein einzelnes Bild-Download und Zuordnen mehr. Backend: GET /export/labels?category_ids=... liefert die Zeilen (JSON); den QR-Inhalt setzt das Web mit window.location.origin dazu. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,7 @@ from ..models import (
|
||||
DatePrecision,
|
||||
FieldDefinition,
|
||||
Group,
|
||||
Item,
|
||||
Location,
|
||||
Lot,
|
||||
Movement,
|
||||
@@ -251,6 +252,47 @@ def export_backup_json(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/export/labels")
|
||||
def export_labels(
|
||||
category_ids: str | None = None,
|
||||
db: Session = Depends(get_db),
|
||||
_: User = Depends(get_current_user),
|
||||
) -> list[dict]:
|
||||
"""Zeilen für den QR-Etiketten-Export (P-touch & Co.) – je Einzelstück eine.
|
||||
|
||||
``category_ids`` (z.B. "1,3") grenzt auf Kategorien samt Unterkategorien ein;
|
||||
leer = alle Einzelstücke. Den QR-Inhalt (…/i/<UID>) setzt die Weboberfläche
|
||||
dazu, weil nur sie die öffentliche Adresse kennt.
|
||||
"""
|
||||
from .categories import descendant_ids
|
||||
|
||||
ids: set[int] | None = None
|
||||
if category_ids:
|
||||
ids = set()
|
||||
for part in category_ids.split(","):
|
||||
teil = part.strip()
|
||||
if teil.isdigit():
|
||||
ids |= descendant_ids(db, int(teil))
|
||||
|
||||
query = db.query(Item)
|
||||
if ids is not None:
|
||||
query = (
|
||||
query.join(Product, Item.product_id == Product.id)
|
||||
.filter(Product.category_id.in_(ids))
|
||||
)
|
||||
rows: list[dict] = []
|
||||
for item in query.order_by(Item.id).all():
|
||||
product = item.product
|
||||
rows.append({
|
||||
"uid": item.uid,
|
||||
"product": product.name if product else "",
|
||||
"brand": (product.brand if product else "") or "",
|
||||
"category": _category_path(db, product.category) if product else "",
|
||||
"location": item.location.name if item.location else "",
|
||||
})
|
||||
return rows
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Import (nur additiv)
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user