fix - close oe unclose quota in dashboeard

This commit is contained in:
2025-12-08 12:08:52 +03:30
parent 992f993e5b
commit d825aa7cd5
2 changed files with 14 additions and 4 deletions

View File

@@ -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

View File

@@ -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}