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