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.exceptions import APIException
from rest_framework.response import Response 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.api import BaseViewSet
from apps.core.mixins.search_mixin import DynamicSearchMixin from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin 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 """ """ quotas that related to my organization and product """
organization = get_organization_by_user(request.user) organization = get_organization_by_user(request.user)
quota = product_models.Quota.objects.filter( org_child = get_all_org_child(organization)
Q( org_child.append(organization)
distributions_assigned__in=product_models.QuotaDistribution.objects.filter(
Q(assigned_organization=organization) | if organization.type.key == 'ADM':
Q(assigner_organization=organization) quota = product_models.Quota.objects.filter(
) product=self.get_object()
) | ).distinct()
Q(registerer_organization=organization), else:
product=self.get_object() quota = product_models.Quota.objects.filter(
).distinct() 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) page = self.paginate_queryset(quota)
if page is not None: if page is not None: