fix - dashboard quota filter by date
This commit is contained in:
@@ -3,7 +3,6 @@ from django.db.models import Sum, Count, Q
|
|||||||
from django.db.models.functions import Coalesce
|
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.core.services.filter.search import DynamicSearchService
|
from apps.core.services.filter.search import DynamicSearchService
|
||||||
from apps.product.models import OrganizationQuotaStats, QuotaDistribution
|
from apps.product.models import OrganizationQuotaStats, QuotaDistribution
|
||||||
|
|
||||||
@@ -16,14 +15,12 @@ class QuotaDashboardService:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dashboard(self, org: Organization, start_date: str = None, end_date: str = None,
|
def get_dashboard(self, org: Organization, start_date: str = None, end_date: str = None,
|
||||||
search_fields: list[str] = None, quota_is_closed: bool = False):
|
search_fields: list[str] = None, quota_is_closed: bool = False):
|
||||||
orgs_child = get_all_org_child(org=org)
|
|
||||||
orgs_child.append(org)
|
|
||||||
|
|
||||||
if org.type.key == 'ADM':
|
if org.type.key == 'ADM':
|
||||||
org_quota_stats = OrganizationQuotaStats.objects.filter(quota__is_closed=quota_is_closed, )
|
org_quota_stats = OrganizationQuotaStats.objects.filter(stat_type='quota', quota__is_closed=quota_is_closed)
|
||||||
else:
|
else:
|
||||||
org_quota_stats = OrganizationQuotaStats.objects.filter(
|
org_quota_stats = OrganizationQuotaStats.objects.filter(
|
||||||
organization__in=orgs_child,
|
organization=org,
|
||||||
quota__is_closed=quota_is_closed,
|
quota__is_closed=quota_is_closed,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -441,7 +441,8 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, QuotaDashboardService, viewsets
|
|||||||
|
|
||||||
queryset = self.filter_query(
|
queryset = self.filter_query(
|
||||||
self.get_queryset(visibility_by_org_scope=True).filter(
|
self.get_queryset(visibility_by_org_scope=True).filter(
|
||||||
is_closed=False)) # return by search param or all objects
|
is_closed=False)
|
||||||
|
) # return by search param or all objects
|
||||||
|
|
||||||
# paginate queryset
|
# paginate queryset
|
||||||
page = self.paginate_queryset(
|
page = self.paginate_queryset(
|
||||||
|
|||||||
@@ -134,6 +134,9 @@ class QuotaDistributionViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewS
|
|||||||
else:
|
else:
|
||||||
queryset = queryset.filter(Q(quota__is_closed=False))
|
queryset = queryset.filter(Q(quota__is_closed=False))
|
||||||
|
|
||||||
|
if query.get('product_id'):
|
||||||
|
queryset = queryset.filter(Q(quota__product_id=int(query.get('product_id'))))
|
||||||
|
|
||||||
queryset = self.filter_query(self.filter_queryset(queryset))
|
queryset = self.filter_query(self.filter_queryset(queryset))
|
||||||
|
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class InventoryEntryViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet,
|
|||||||
search_fields = [
|
search_fields = [
|
||||||
"distribution__distribution_id",
|
"distribution__distribution_id",
|
||||||
"organization__name",
|
"organization__name",
|
||||||
|
"org_quota_stat__quota__product__name",
|
||||||
|
"delivery_address",
|
||||||
"weight",
|
"weight",
|
||||||
"balance",
|
"balance",
|
||||||
"lading_number",
|
"lading_number",
|
||||||
@@ -128,7 +130,7 @@ class InventoryEntryViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet,
|
|||||||
organization=org,
|
organization=org,
|
||||||
quota_id=pk
|
quota_id=pk
|
||||||
)
|
)
|
||||||
queryset = self.filter_query(entries) # return by search param or all objects
|
queryset = self.filter_query(self.filter_queryset(entries)) # return by search param or all objects
|
||||||
|
|
||||||
# paginate & response
|
# paginate & response
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
@@ -150,7 +152,7 @@ class InventoryEntryViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet,
|
|||||||
entries = self.get_queryset(
|
entries = self.get_queryset(
|
||||||
visibility_by_org_scope=True
|
visibility_by_org_scope=True
|
||||||
) if org.free_visibility_by_scope else self.get_queryset().filter(organization=org)
|
) if org.free_visibility_by_scope else self.get_queryset().filter(organization=org)
|
||||||
queryset = self.filter_query(entries) # return by search param or all objects
|
queryset = self.filter_query(self.filter_queryset(entries)) # return by search param or all objects
|
||||||
|
|
||||||
# paginate & response
|
# paginate & response
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
|
|||||||
Reference in New Issue
Block a user