|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
from typing import Any, Optional
|
|
|
|
|
|
from app.schemas.db.public_inventory import PublicPoundQrRead
|
|
|
+from app.schemas.pl.transport import PublicPoundQrcodeItemRead
|
|
|
from app.services.db.mappers import inventory_date_to_api
|
|
|
|
|
|
|
|
|
@@ -28,3 +29,57 @@ def build_public_pound_qr_read(row: Any, *, quantity_unit: Optional[str] = None)
|
|
|
quantity_unit=unit,
|
|
|
remarks=(row.remark or None) if getattr(row, "remark", None) else None,
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+def build_pound_qrcode_items_for_plan(
|
|
|
+ db,
|
|
|
+ *,
|
|
|
+ tenant_no: str,
|
|
|
+ plan_id: str,
|
|
|
+ transport_id: str,
|
|
|
+) -> list[PublicPoundQrcodeItemRead]:
|
|
|
+ from app.models.db_models import DbInboundOutbound
|
|
|
+ from app.models.pl_models import PlTransportDbLink
|
|
|
+
|
|
|
+ links = (
|
|
|
+ db.query(PlTransportDbLink)
|
|
|
+ .filter(
|
|
|
+ PlTransportDbLink.tenant_no == tenant_no,
|
|
|
+ PlTransportDbLink.plan_id == plan_id,
|
|
|
+ PlTransportDbLink.transport_id == transport_id,
|
|
|
+ PlTransportDbLink.del_flag == 0,
|
|
|
+ )
|
|
|
+ .all()
|
|
|
+ )
|
|
|
+ items: list[PublicPoundQrcodeItemRead] = []
|
|
|
+ seen: set[str] = set()
|
|
|
+ for link in links:
|
|
|
+ inv_id = (link.db_inventory_id or "").strip()
|
|
|
+ if not inv_id or inv_id in seen:
|
|
|
+ continue
|
|
|
+ if not (link.db_purchase_plan_id or "").strip():
|
|
|
+ continue
|
|
|
+ inv = (
|
|
|
+ db.query(DbInboundOutbound)
|
|
|
+ .filter(
|
|
|
+ DbInboundOutbound.id == inv_id,
|
|
|
+ DbInboundOutbound.tenant_no == tenant_no,
|
|
|
+ DbInboundOutbound.del_flag == 0,
|
|
|
+ )
|
|
|
+ .first()
|
|
|
+ )
|
|
|
+ if not inv:
|
|
|
+ continue
|
|
|
+ seen.add(inv_id)
|
|
|
+ bt = (inv.business_type or "").strip()
|
|
|
+ pc = (inv.partner_company or "").strip()
|
|
|
+ items.append(
|
|
|
+ PublicPoundQrcodeItemRead(
|
|
|
+ inventory_id=inv.id,
|
|
|
+ business_type=bt,
|
|
|
+ partner_company=pc,
|
|
|
+ label=build_pound_qr_label(bt, pc),
|
|
|
+ )
|
|
|
+ )
|
|
|
+ return items
|
|
|
+
|