fix - transaction dashboard in admin / my org childs

This commit is contained in:
2025-11-26 12:40:10 +03:30
parent f79c25485b
commit 7c1fb57934

View File

@@ -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"),