|
|
@@ -21,6 +21,7 @@ from app.models.pl_models import (
|
|
|
PlOutboundOrderItem,
|
|
|
PlPlan,
|
|
|
PlPlanProduct,
|
|
|
+ PlPlanProductBrandQty,
|
|
|
PlTransport,
|
|
|
PlTransportDbLink,
|
|
|
)
|
|
|
@@ -502,6 +503,33 @@ def enrich_io_order_dict(
|
|
|
if public_unit_as_label:
|
|
|
it["unit"] = it.get("unitLabel") or resolve_unit_label(unit_map, it.get("unit"))
|
|
|
|
|
|
+ brand_summary_by_pp: dict[str, str] = {}
|
|
|
+ if product_ids:
|
|
|
+ brand_rows = (
|
|
|
+ db.query(PlPlanProductBrandQty)
|
|
|
+ .filter(
|
|
|
+ PlPlanProductBrandQty.plan_product_id.in_(product_ids),
|
|
|
+ PlPlanProductBrandQty.tenant_no == tenant_no,
|
|
|
+ PlPlanProductBrandQty.del_flag == 0,
|
|
|
+ )
|
|
|
+ .order_by(PlPlanProductBrandQty.order_num.asc())
|
|
|
+ .all()
|
|
|
+ )
|
|
|
+ grouped: dict[str, list[str]] = {}
|
|
|
+ for br in brand_rows:
|
|
|
+ qty = Decimal(str(br.qty or 0))
|
|
|
+ if qty <= 0:
|
|
|
+ continue
|
|
|
+ name = (br.brand_name or "").strip() or "未命名品牌"
|
|
|
+ # 去掉多余尾零,如 6.000 -> 6
|
|
|
+ qty_text = format(qty.normalize(), "f")
|
|
|
+ grouped.setdefault(br.plan_product_id, []).append(f"{name} {qty_text}")
|
|
|
+ brand_summary_by_pp = {k: " / ".join(v) for k, v in grouped.items()}
|
|
|
+
|
|
|
+ for it in raw_items:
|
|
|
+ pp_id = it.get("planProductId") or ""
|
|
|
+ it["brandSummary"] = brand_summary_by_pp.get(pp_id) or None
|
|
|
+
|
|
|
return data
|
|
|
|
|
|
|