quotas information by product - change broker & attribute sale unit
This commit is contained in:
@@ -103,6 +103,27 @@ class ProductViewSet(viewsets.ModelViewSet):
|
||||
|
||||
return Response(product_data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=True,
|
||||
url_path='quotas_information',
|
||||
url_name='quotas_information',
|
||||
name='quotas_information'
|
||||
)
|
||||
@transaction.atomic
|
||||
def quotas_information_by_product(self, request, pk=None):
|
||||
""" get quotas information of a product """
|
||||
|
||||
quotas = product_models.Quota.objects.select_related('product').filter(
|
||||
product_id=pk, is_closed=False
|
||||
)
|
||||
|
||||
try:
|
||||
quota_serializer = product_serializers.QuotaSerializer(quotas, many=True).data
|
||||
return Response(quota_serializer, status=status.HTTP_200_OK)
|
||||
except APIException as e:
|
||||
raise APIException(detail="data error", code=400)
|
||||
|
||||
@action(
|
||||
methods=['put'],
|
||||
detail=True,
|
||||
@@ -136,7 +157,7 @@ class ProductViewSet(viewsets.ModelViewSet):
|
||||
|
||||
|
||||
class AttributeViewSet(viewsets.ModelViewSet):
|
||||
""" attributes of reference product """
|
||||
""" attributes of reference product """ #
|
||||
|
||||
queryset = product_models.Attribute.objects.all()
|
||||
serializer_class = product_serializers.AttributeSerializer
|
||||
|
||||
@@ -44,6 +44,12 @@ class AttributeSerializer(serializers.ModelSerializer):
|
||||
'id': instance.product.id,
|
||||
'name': instance.product.name
|
||||
}
|
||||
|
||||
if instance.type:
|
||||
representation['type'] = {
|
||||
'id': instance.type.id,
|
||||
'unit': instance.type.unit
|
||||
}
|
||||
return representation
|
||||
|
||||
|
||||
@@ -70,6 +76,7 @@ class BrokerSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.Broker
|
||||
fields = '__all__'
|
||||
depth = 0
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
@@ -83,6 +90,12 @@ class BrokerSerializer(serializers.ModelSerializer):
|
||||
instance.product
|
||||
).data
|
||||
|
||||
if instance.calculation_strategy:
|
||||
representation['calculation_strategy'] = {
|
||||
'id': instance.calculation_strategy.id,
|
||||
'unit': instance.calculation_strategy.unit
|
||||
}
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user