From 1f834ff3c5c1fbfae1a82cfc63c42c28e056e1c7 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Wed, 10 Dec 2025 17:00:26 +0330 Subject: [PATCH] fix - related product quotas in admin account --- .../web/api/v1/viewsets/product_api.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/product/web/api/v1/viewsets/product_api.py b/apps/product/web/api/v1/viewsets/product_api.py index 95d4162..deb046f 100644 --- a/apps/product/web/api/v1/viewsets/product_api.py +++ b/apps/product/web/api/v1/viewsets/product_api.py @@ -9,6 +9,7 @@ from rest_framework.decorators import action from rest_framework.exceptions import APIException from rest_framework.response import Response +from apps.authentication.services.service import get_all_org_child from apps.core.api import BaseViewSet from apps.core.mixins.search_mixin import DynamicSearchMixin from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin @@ -136,16 +137,24 @@ class ProductViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin, """ quotas that related to my organization and product """ organization = get_organization_by_user(request.user) - quota = product_models.Quota.objects.filter( - Q( - distributions_assigned__in=product_models.QuotaDistribution.objects.filter( - Q(assigned_organization=organization) | - Q(assigner_organization=organization) - ) - ) | - Q(registerer_organization=organization), - product=self.get_object() - ).distinct() + org_child = get_all_org_child(organization) + org_child.append(organization) + + if organization.type.key == 'ADM': + quota = product_models.Quota.objects.filter( + product=self.get_object() + ).distinct() + else: + quota = product_models.Quota.objects.filter( + Q( + distributions_assigned__in=product_models.QuotaDistribution.objects.filter( + Q(assigned_organization__in=org_child) | + Q(assigner_organization__in=org_child) + ) + ) | + Q(registerer_organization=organization), + product=self.get_object() + ).distinct() page = self.paginate_queryset(quota) if page is not None: