fix - related product quotas in admin account

This commit is contained in:
2025-12-10 17:00:26 +03:30
parent 1a44ce9978
commit 1f834ff3c5

View File

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