fix - transaction dashboard in admin / my org childs
This commit is contained in:
@@ -3,17 +3,33 @@ from collections import defaultdict
|
|||||||
from django.db.models import Sum, Count, Case, When, Q, Value
|
from django.db.models import Sum, Count, Case, When, Q, Value
|
||||||
from django.db.models.functions import Coalesce
|
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
|
from apps.warehouse.models import InventoryQuotaSaleTransaction, InventoryQuotaSaleItem
|
||||||
|
|
||||||
|
|
||||||
class TransactionDashboardService:
|
class TransactionDashboardService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dashboard(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(
|
transactions = InventoryQuotaSaleTransaction.objects.filter(
|
||||||
seller_organization=org
|
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(
|
transaction_stats = transactions.aggregate(
|
||||||
total_transactions=Count("id"),
|
total_transactions=Count("id"),
|
||||||
success_transactions=Count("id", filter=Q(transaction_status="success")),
|
success_transactions=Count("id", filter=Q(transaction_status="success")),
|
||||||
@@ -24,10 +40,6 @@ class TransactionDashboardService:
|
|||||||
unique_ranchers=Count("rancher", distinct=True),
|
unique_ranchers=Count("rancher", distinct=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
items = InventoryQuotaSaleItem.objects.filter(
|
|
||||||
transaction__seller_organization=org
|
|
||||||
).select_related("gov_product", "free_product")
|
|
||||||
|
|
||||||
products_stats = items.values(
|
products_stats = items.values(
|
||||||
product_id=Case(
|
product_id=Case(
|
||||||
When(gov_product__isnull=False, then="gov_product_id"),
|
When(gov_product__isnull=False, then="gov_product_id"),
|
||||||
|
|||||||
Reference in New Issue
Block a user