From 7c1fb5793444cd6db10032445cf80c1d9d619c8c Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Wed, 26 Nov 2025 12:40:10 +0330 Subject: [PATCH] fix - transaction dashboard in admin / my org childs --- .../services/transaction_dashboard_service.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/warehouse/services/transaction_dashboard_service.py b/apps/warehouse/services/transaction_dashboard_service.py index a8c7d53..a3c9db6 100644 --- a/apps/warehouse/services/transaction_dashboard_service.py +++ b/apps/warehouse/services/transaction_dashboard_service.py @@ -3,16 +3,32 @@ from collections import defaultdict from django.db.models import Sum, Count, Case, When, Q, Value from django.db.models.functions import Coalesce +from apps.authentication.models import Organization +from apps.authentication.services.service import get_all_org_child from apps.warehouse.models import InventoryQuotaSaleTransaction, InventoryQuotaSaleItem class TransactionDashboardService: @staticmethod - def get_dashboard(org): - transactions = InventoryQuotaSaleTransaction.objects.filter( - seller_organization=org - ) + def get_dashboard(org: Organization): + + orgs_child = get_all_org_child(org=org) + orgs_child.append(org) + + if org.type.key == 'ADM': + transactions = InventoryQuotaSaleTransaction.objects.all() + + items = InventoryQuotaSaleItem.objects.all().select_related("gov_product", "free_product") + + else: + transactions = InventoryQuotaSaleTransaction.objects.filter( + seller_organization__in=orgs_child + ) + + items = InventoryQuotaSaleItem.objects.filter( + transaction__seller_organization__in=orgs_child + ).select_related("gov_product", "free_product") transaction_stats = transactions.aggregate( total_transactions=Count("id"), @@ -24,10 +40,6 @@ class TransactionDashboardService: unique_ranchers=Count("rancher", distinct=True), ) - items = InventoryQuotaSaleItem.objects.filter( - transaction__seller_organization=org - ).select_related("gov_product", "free_product") - products_stats = items.values( product_id=Case( When(gov_product__isnull=False, then="gov_product_id"),