From d825aa7cd5ef2e3c1f41a84e6688f48a8b7c444f Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 8 Dec 2025 12:08:52 +0330 Subject: [PATCH] fix - close oe unclose quota in dashboeard --- apps/product/services/quota_dashboard_service.py | 7 ++++--- apps/product/web/api/v1/viewsets/quota_api.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/product/services/quota_dashboard_service.py b/apps/product/services/quota_dashboard_service.py index 0ee8110..48b6445 100644 --- a/apps/product/services/quota_dashboard_service.py +++ b/apps/product/services/quota_dashboard_service.py @@ -15,15 +15,16 @@ class QuotaDashboardService: @staticmethod def get_dashboard(self, org: Organization, start_date: str = None, end_date: str = None, - search_fields: list[str] = None): + 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': - org_quota_stats = OrganizationQuotaStats.objects.all() + org_quota_stats = OrganizationQuotaStats.objects.filter(quota__is_closed=quota_is_closed, ) else: org_quota_stats = OrganizationQuotaStats.objects.filter( - organization__in=orgs_child + organization__in=orgs_child, + quota__is_closed=quota_is_closed, ) # filter queryset (transactions & items) by date diff --git a/apps/product/web/api/v1/viewsets/quota_api.py b/apps/product/web/api/v1/viewsets/quota_api.py index e690110..88aa71f 100644 --- a/apps/product/web/api/v1/viewsets/quota_api.py +++ b/apps/product/web/api/v1/viewsets/quota_api.py @@ -369,15 +369,20 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, QuotaDashboardService, viewsets query_param = self.request.query_params # noqa + # filter by date 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 + # filter by quota is close or open + is_closed = True if 'is_closed' in query_param.keys() else False + quota_dashboard = self.get_dashboard( self, org=get_organization_by_user(request.user), start_date=start_date, end_date=end_date, search_fields=self.search_fields, + quota_is_closed=is_closed ) return Response(quota_dashboard) @@ -401,9 +406,13 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, QuotaDashboardService, viewsets 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 + # filter by quota is close or open + is_closed = True if 'is_closed' in query_param.keys() else False + # get organization quota stats and get product ids org_quota_stat = OrganizationQuotaStats.objects.select_related('organization', 'quota').filter( - organization=org + organization=org, + quota__is_closed=is_closed ) if not org.type.key == 'ADM' else OrganizationQuotaStats.objects.select_related('organization', 'quota').all() products = {f'{stat.quota.product.name}': stat.quota.product.id for stat in org_quota_stat}