some changes in quota serializer
This commit is contained in:
@@ -64,7 +64,19 @@ class AttributeValueSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = product_models.AttributeValue
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"attribute",
|
||||
"value",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom Output of attribute values """
|
||||
representation = super().to_representation(instance)
|
||||
if instance.attribute:
|
||||
representation['attribute_name'] = instance.attribute.name
|
||||
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
instance.quota = validated_data.get('quota', instance.quota)
|
||||
|
||||
@@ -10,7 +10,6 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.Quota
|
||||
fields = '__all__'
|
||||
depth = 0
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
@@ -40,10 +39,9 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
many=True
|
||||
).data
|
||||
|
||||
representation['limit_by_organizations'] = OrganizationSerializer(
|
||||
instance.limit_by_organizations.all(),
|
||||
many=True
|
||||
).data
|
||||
representation['limit_by_organizations'] = [
|
||||
{"name": limit.name, "id": limit.id} for limit in instance.limit_by_organizations.all()
|
||||
]
|
||||
|
||||
return representation
|
||||
|
||||
@@ -89,7 +87,20 @@ class QuotaStatsSerializer(serializers.ModelSerializer):
|
||||
class QuotaIncentiveAssignmentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.QuotaIncentiveAssignment
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"incentive_plan",
|
||||
"heavy_value",
|
||||
"light_value",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom Output for incentive plans """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
representation['incentive_plan_name'] = instance.incentive_plan.name
|
||||
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
""" Custom Update """
|
||||
@@ -106,7 +117,19 @@ class QuotaIncentiveAssignmentSerializer(serializers.ModelSerializer):
|
||||
class QuotaBrokerValueSerializer(serializers.ModelSerializer): # noqa
|
||||
class Meta:
|
||||
model = product_models.QuotaBrokerValue
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"broker",
|
||||
"value",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom Output of broker values """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
representation['broker_name'] = instance.broker.name
|
||||
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
""" Custom Update """
|
||||
@@ -122,7 +145,13 @@ class QuotaBrokerValueSerializer(serializers.ModelSerializer): # noqa
|
||||
class QuotaLiveStockAllocationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.QuotaLivestockAllocation
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"livestock_group",
|
||||
"livestock_type",
|
||||
"livestock_subtype",
|
||||
"quantity_kg",
|
||||
]
|
||||
extra_kwargs = {
|
||||
'livestock_group': {
|
||||
'required': False
|
||||
@@ -159,7 +188,12 @@ class QuotaLiveStockAllocationSerializer(serializers.ModelSerializer):
|
||||
class QuotaLiveStockAgeLimitationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.QuotaLiveStockAgeLimitation
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"livestock_type",
|
||||
"livestock_subtype",
|
||||
"age_month",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" custom output for livestock type """
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from apps.product.web.api.v1.serializers import product_serializers as product_serializers
|
||||
from apps.product.web.api.v1.serializers import quota_serializers
|
||||
from apps.product.exceptions import QuotaExpiredTimeException
|
||||
from apps.core.pagination import CustomPageNumberPagination
|
||||
from apps.product.services import get_products_in_warehouse
|
||||
from apps.product.web.api.v1.viewsets import product_api
|
||||
from common.helpers import get_organization_by_user
|
||||
@@ -35,6 +36,7 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
||||
queryset = product_models.Quota.objects.all()
|
||||
serializer_class = quota_serializers.QuotaSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
CustomPageNumberPagination.page_size = 5
|
||||
search_fields = ['']
|
||||
|
||||
@transaction.atomic
|
||||
|
||||
Reference in New Issue
Block a user