first move for product statistics
This commit is contained in:
2
.idea/Rasaddam_Backend.iml
generated
2
.idea/Rasaddam_Backend.iml
generated
@@ -14,7 +14,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<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" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PyDocumentationSettings">
|
<component name="PyDocumentationSettings">
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<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>
|
</project>
|
||||||
@@ -114,7 +114,8 @@ class Product(BaseModel):
|
|||||||
).aggregate(total_entry=models.Sum('warehouse_entry'))['total_entry'] or 0
|
).aggregate(total_entry=models.Sum('warehouse_entry'))['total_entry'] or 0
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'product': self.id,
|
'product_id': self.id,
|
||||||
|
'product_name': self.name,
|
||||||
'quotas_count': quotas_count,
|
'quotas_count': quotas_count,
|
||||||
'total_quotas_weight': total_quotas_weight,
|
'total_quotas_weight': total_quotas_weight,
|
||||||
'total_remaining_quotas_weight': total_remaining_quotas_weight,
|
'total_remaining_quotas_weight': total_remaining_quotas_weight,
|
||||||
|
|||||||
@@ -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'broker', product_api.BrokerViewSet, basename='broker')
|
||||||
router.register(r'sale_unit', product_api.SaleUnitViewSet, basename='sale_unit')
|
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'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', quota_api.QuotaViewSet, basename='quota')
|
||||||
router.register(r'quota_distribution', distribution_apis.QuotaDistributionViewSet, basename='quota_distribution')
|
router.register(r'quota_distribution', distribution_apis.QuotaDistributionViewSet, basename='quota_distribution')
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from apps.product.web.api.v1.serializers import product_serializers as product_serializers
|
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 rest_framework.exceptions import APIException
|
||||||
from apps.product import models as product_models
|
from apps.product import models as product_models
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
@@ -115,6 +116,37 @@ class ProductViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
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):
|
class AttributeViewSet(viewsets.ModelViewSet):
|
||||||
""" attributes of reference product """ #
|
""" attributes of reference product """ #
|
||||||
|
|
||||||
|
|||||||
@@ -382,9 +382,9 @@ class QuotaViewSet(viewsets.ModelViewSet, DynamicSearchMixin): # noqa
|
|||||||
@action(
|
@action(
|
||||||
methods=['get'],
|
methods=['get'],
|
||||||
detail=False,
|
detail=False,
|
||||||
url_path='quotas_statistics',
|
url_path='statistics_by_product',
|
||||||
url_name='quotas_statistics',
|
url_name='statistics_by_product',
|
||||||
name='quotas_statistics'
|
name='statistics_by_product'
|
||||||
)
|
)
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def quotas_statistics_by_product(self, request):
|
def quotas_statistics_by_product(self, request):
|
||||||
|
|||||||
Reference in New Issue
Block a user