feat(backend): add public pound-qr endpoint by inventory id

Expose a read-only payload for the shared weighbridge QR card without auth.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-09-13 09:24:09 +08:00
1 parent 8994849292
commit 87ed40512c
4 files changed
+108

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
"""公开磅单二维码只读接口。"""
from datetime import date
from types import SimpleNamespace
from fastapi.testclient import TestClient
from app.main import app
from app.services.db.pound_qr_public import (
build_pound_qr_label,
build_public_pound_qr_read,
)
client = TestClient(app)
def test_build_pound_qr_label():
assert build_pound_qr_label("出库", "合肥德泽") == "出库 · 合肥德泽"
assert build_pound_qr_label("入库", "") == "入库"
assert build_pound_qr_label("", "安庆山峡") == "安庆山峡"
def test_build_public_pound_qr_read_maps_fields():
row = SimpleNamespace(
id="inv-1",
date=date(2026, 9, 12),
business_type="出库",
vehicle_no="皖AM8516",
partner_company="合肥德泽化工科技有限公司",
product="30% 工业硫酸",
specification="30%",
quantity=10.0,
remark="注意安全",
)
read = build_public_pound_qr_read(row, quantity_unit="吨")
dump = read.model_dump(by_alias=True)
assert dump["id"] == "inv-1"
assert dump["date"] == "2026-09-12"
assert dump["businessType"] == "出库"
assert dump["vehicleNo"] == "皖AM8516"
assert dump["partnerCompany"] == "合肥德泽化工科技有限公司"
assert dump["product"] == "30% 工业硫酸"
assert dump["specification"] == "30%"
assert dump["quantity"] == 10.0
assert dump["quantityUnit"] == "吨"
assert dump["remarks"] == "注意安全"
def test_pound_qr_missing_returns_404():
resp = client.get("/api/public/db/inventory/__missing_pound_qr_id__/pound-qr")
assert resp.status_code == 404