fix - hesab asli was removed from transaction dashboard

This commit is contained in:
2025-11-30 11:31:24 +03:30
parent 0de6e7cb40
commit 634d50c4cd
2 changed files with 76 additions and 4 deletions

View File

@@ -118,9 +118,13 @@ class TransactionDashboardService:
# share: {"name": "", "price": "", ....}
name = share.get("name")
price = share.get("price", 0)
shaba = share.get("shaba", 0) # noqa
share_totals[name]["total_price"] += price
share_totals[name]["count"] += 1
share_totals[name]["shaba"] = shaba # noqa
share_totals = merge_by_shaba_single_name(share_totals)
product["item_share_stats"] = sorted(
[
@@ -147,3 +151,27 @@ class TransactionDashboardService:
"product_summary": list(products_stats),
"brokers_sharing_summary": share_totals
}
def merge_by_shaba_single_name(data): # noqa
grouped = defaultdict(lambda: {"name": None, "total_price": 0, "count": 0, "shaba": None}) # noqa
for name, info in data.items(): # noqa
shaba = info["shaba"] # noqa
if grouped[shaba]["name"] is None:
grouped[shaba]["name"] = name
grouped[shaba]["total_price"] += info["total_price"]
grouped[shaba]["count"] += info["count"]
grouped[shaba]["shaba"] = shaba # noqa
final_result = {}
for shaba, g in grouped.items(): # noqa
final_result[g["name"]] = {
"total_price": g["total_price"],
"count": g["count"],
"shaba": g["shaba"], # noqa
}
return final_result