add - filter on transaction dashboard
This commit is contained in:
2
.idea/Rasaddam_Backend.iml
generated
2
.idea/Rasaddam_Backend.iml
generated
@@ -14,7 +14,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$" />
|
||||||
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.10 (env)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PyDocumentationSettings">
|
<component name="PyDocumentationSettings">
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.10 (env)" />
|
<option name="sdkName" value="Python 3.10 (env)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (env)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
@@ -5,13 +5,14 @@ from django.db.models.functions import Coalesce
|
|||||||
|
|
||||||
from apps.authentication.models import Organization
|
from apps.authentication.models import Organization
|
||||||
from apps.authentication.services.service import get_all_org_child
|
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
|
from apps.warehouse.models import InventoryQuotaSaleTransaction, InventoryQuotaSaleItem
|
||||||
|
|
||||||
|
|
||||||
class TransactionDashboardService:
|
class TransactionDashboardService:
|
||||||
|
|
||||||
@staticmethod
|
@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 = get_all_org_child(org=org)
|
||||||
orgs_child.append(org)
|
orgs_child.append(org)
|
||||||
@@ -30,6 +31,19 @@ class TransactionDashboardService:
|
|||||||
transaction__seller_organization__in=orgs_child
|
transaction__seller_organization__in=orgs_child
|
||||||
).select_related("gov_product", "free_product")
|
).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(
|
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")),
|
||||||
@@ -89,7 +103,7 @@ class TransactionDashboardService:
|
|||||||
for item in items_by_product.get(pid, []):
|
for item in items_by_product.get(pid, []):
|
||||||
if item.item_share:
|
if item.item_share:
|
||||||
for share in item.item_share:
|
for share in item.item_share:
|
||||||
# share: {"name": ..., "price": ..., "shaba": ...}
|
# share: {"name": "", "price": "", ....}
|
||||||
name = share.get("name")
|
name = share.get("name")
|
||||||
price = share.get("price", 0)
|
price = share.get("price", 0)
|
||||||
|
|
||||||
|
|||||||
@@ -230,9 +230,20 @@ class InventoryQuotaSaleTransactionViewSet(
|
|||||||
"""
|
"""
|
||||||
dashboard of full detail of all my transactions
|
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)
|
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)
|
return Response(transaction_dashboard_data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user