first move for product statistics

This commit is contained in:
2025-08-02 11:04:46 +03:30
parent 62b7098486
commit 699b5ab6fd
6 changed files with 40 additions and 6 deletions

View File

@@ -14,7 +14,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.10 (bazrasienv)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10 (env)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">

2
.idea/misc.xml generated
View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (bazrasienv)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (env)" project-jdk-type="Python SDK" />
</project>

View File

@@ -114,7 +114,8 @@ class Product(BaseModel):
).aggregate(total_entry=models.Sum('warehouse_entry'))['total_entry'] or 0
data = {
'product': self.id,
'product_id': self.id,
'product_name': self.name,
'quotas_count': quotas_count,
'total_quotas_weight': total_quotas_weight,
'total_remaining_quotas_weight': total_remaining_quotas_weight,

View File

@@ -14,6 +14,7 @@ router.register(r'attribute_value', product_api.AttributeValueViewSet, basename=
router.register(r'broker', product_api.BrokerViewSet, basename='broker')
router.register(r'sale_unit', product_api.SaleUnitViewSet, basename='sale_unit')
router.register(r'incentive_plan', product_api.IncentivePlanViewSet, basename='incentive_plan')
router.register(r'stats', product_api.ProductStatsViewSet, basename='stats')
router.register(r'quota', quota_api.QuotaViewSet, basename='quota')
router.register(r'quota_distribution', distribution_apis.QuotaDistributionViewSet, basename='quota_distribution')

View File

@@ -1,5 +1,6 @@
import datetime
from apps.product.web.api.v1.serializers import product_serializers as product_serializers
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
@@ -115,6 +116,37 @@ class ProductViewSet(viewsets.ModelViewSet):
return Response(e, status=status.HTTP_204_NO_CONTENT)
class ProductStatsViewSet(viewsets.ModelViewSet):
""" product statistics by its quotas """
queryset = product_models.ProductStats.objects.all()
serializer_class = product_serializers.ProductStatsSerializer
@action(
methods=['get'],
detail=False,
url_path='my_products_stat',
url_name='my_products_stat',
name='my_products_stat'
)
def my_products_stat(self, request):
""" my organization products with statistics """
try:
organization = get_organization_by_user(request.user)
product_stats = self.queryset.filter(organization=organization)
page = self.paginate_queryset(product_stats) # noqa
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.serializer_class(product_stats, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
except APIException as e:
raise e
class AttributeViewSet(viewsets.ModelViewSet):
""" attributes of reference product """ #

View File

@@ -382,9 +382,9 @@ class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin): # noqa
@action(
methods=['get'],
detail=False,
url_path='quotas_statistics',
url_name='quotas_statistics',
name='quotas_statistics'
url_path='statistics_by_product',
url_name='statistics_by_product',
name='statistics_by_product'
)
@transaction.atomic
def quotas_statistics_by_product(self, request):