add product serialize to broker - quota statistic by product

This commit is contained in:
2025-07-08 11:59:58 +03:30
parent bafd1fbbcb
commit 90b090e848
5 changed files with 41 additions and 5 deletions

View File

@@ -2,6 +2,8 @@ import datetime
from apps.product.web.api.v1 import product_serializers as product_serializers
from apps.product.exceptions import QuotaExpiredTimeException
from apps.product.services import get_products_in_warehouse
from common.helpers import get_organization_by_user
from rest_framework.exceptions import APIException
from apps.product import models as product_models
from rest_framework.response import Response
@@ -68,6 +70,8 @@ class ProductViewSet(viewsets.ModelViewSet):
serializer_class = product_serializers.ProductSerializer
def list(self, request, *args, **kwargs):
""" custom list view """ #
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa
page = self.paginate_queryset(queryset)
@@ -87,13 +91,17 @@ class ProductViewSet(viewsets.ModelViewSet):
)
@transaction.atomic
def quotas_statistics_by_product(self, request):
""" quota statistics of each product """
""" quota statistics of each product in organization warehouse """
quotas_statistics = []
for product in self.queryset:
quotas_statistics.append(product.quota_information())
product_data = []
return Response(quotas_statistics, status=status.HTTP_200_OK)
organization = get_organization_by_user(request.user)
products = get_products_in_warehouse(organization.id)
for product in products:
product_data.append(product.quota_information())
return Response(product_data, status=status.HTTP_200_OK)
@action(
methods=['put'],

View File

@@ -78,6 +78,11 @@ class BrokerSerializer(serializers.ModelSerializer):
instance.organization
).data
if instance.product:
representation['product'] = ProductSerializer(
instance.product
).data
return representation