diff --git a/.idea/Rasaddam_Backend.iml b/.idea/Rasaddam_Backend.iml
index 57ec562..168bde0 100644
--- a/.idea/Rasaddam_Backend.iml
+++ b/.idea/Rasaddam_Backend.iml
@@ -14,7 +14,7 @@
-
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index bbe7f0a..f1b70db 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/apps/warehouse/services/transaction_dashboard_service.py b/apps/warehouse/services/transaction_dashboard_service.py
index fd2bfab..adbd678 100644
--- a/apps/warehouse/services/transaction_dashboard_service.py
+++ b/apps/warehouse/services/transaction_dashboard_service.py
@@ -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)
diff --git a/apps/warehouse/web/api/v1/api.py b/apps/warehouse/web/api/v1/api.py
index d6137b5..a19ab22 100644
--- a/apps/warehouse/web/api/v1/api.py
+++ b/apps/warehouse/web/api/v1/api.py
@@ -230,9 +230,20 @@ class InventoryQuotaSaleTransactionViewSet(
"""
dashboard of full detail of all my transactions
"""
+ query_param = self.request.query_params # noqa
+
+ start_date = query_param.get('start') if 'start' in query_param.keys() else None
+ end_date = query_param.get('end') if 'end' in query_param.keys() else None
+ transaction_status = query_param.get('status') if 'status' in query_param.keys() else None
org = get_organization_by_user(request.user)
- transaction_dashboard_data = self.get_dashboard(org)
+ # filer by date & transaction status
+ transaction_dashboard_data = self.get_dashboard(
+ org,
+ start_date=start_date,
+ end_date=end_date,
+ status=transaction_status
+ )
return Response(transaction_dashboard_data, status=status.HTTP_200_OK)