fix(dashboard): received country pie chart now groups by country_from (寄出国)

This commit is contained in:
2026-08-21 14:44:22 +08:00
parent d2a864c7ca
commit 0955c36f6b
1 file changed
+5 -3
+5 -3
View File
@@ -616,12 +616,14 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db:
sent_country_counts: dict[str, int] = {} sent_country_counts: dict[str, int] = {}
received_country_counts: dict[str, int] = {} received_country_counts: dict[str, int] = {}
for c in all_cards: for c in all_cards:
if not c.country_to:
continue
if c.status in ("pending", "sent", "delivered"): if c.status in ("pending", "sent", "delivered"):
if not c.country_to:
continue
sent_country_counts[c.country_to] = sent_country_counts.get(c.country_to, 0) + 1 sent_country_counts[c.country_to] = sent_country_counts.get(c.country_to, 0) + 1
elif c.status == "received": elif c.status == "received":
received_country_counts[c.country_to] = received_country_counts.get(c.country_to, 0) + 1 if not c.country_from:
continue
received_country_counts[c.country_from] = received_country_counts.get(c.country_from, 0) + 1
sent_country_stats = sorted(sent_country_counts.items(), key=lambda x: -x[1]) sent_country_stats = sorted(sent_country_counts.items(), key=lambda x: -x[1])
received_country_stats = sorted(received_country_counts.items(), key=lambda x: -x[1]) received_country_stats = sorted(received_country_counts.items(), key=lambda x: -x[1])