add - filter on transaction dashboard
This commit is contained in:
@@ -5,13 +5,14 @@ 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.core.services.filter.search import DynamicSearchService
|
||||
from apps.warehouse.models import InventoryQuotaSaleTransaction, InventoryQuotaSaleItem
|
||||
|
||||
|
||||
class TransactionDashboardService:
|
||||
|
||||
@staticmethod
|
||||
def get_dashboard(org: Organization):
|
||||
def get_dashboard(org: Organization, start_date: str = None, end_date: str = None, status: str = None):
|
||||
|
||||
orgs_child = get_all_org_child(org=org)
|
||||
orgs_child.append(org)
|
||||
@@ -30,6 +31,19 @@ class TransactionDashboardService:
|
||||
transaction__seller_organization__in=orgs_child
|
||||
).select_related("gov_product", "free_product")
|
||||
|
||||
# filter queryset by date
|
||||
if start_date and end_date:
|
||||
transactions = DynamicSearchService(
|
||||
queryset=transactions,
|
||||
start=start_date,
|
||||
end=end_date,
|
||||
date_field="create_date",
|
||||
).apply()
|
||||
|
||||
# filer by transaction status
|
||||
if status:
|
||||
transactions = transactions.filter(transaction_status=status)
|
||||
|
||||
transaction_stats = transactions.aggregate(
|
||||
total_transactions=Count("id"),
|
||||
success_transactions=Count("id", filter=Q(transaction_status="success")),
|
||||
@@ -89,7 +103,7 @@ class TransactionDashboardService:
|
||||
for item in items_by_product.get(pid, []):
|
||||
if item.item_share:
|
||||
for share in item.item_share:
|
||||
# share: {"name": ..., "price": ..., "shaba": ...}
|
||||
# share: {"name": "", "price": "", ....}
|
||||
name = share.get("name")
|
||||
price = share.get("price", 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user