rancher check unique - pos free products check unique - 500 error handling
This commit is contained in:
@@ -35,3 +35,13 @@ class QuotaLimitByOrganizationException(APIException):
|
||||
status_code = status.HTTP_400_BAD_REQUEST
|
||||
default_detail = "سازمان انتخاب شده در بین سامان های انتخاب شده برای توزیع سهمیه وجود ندارد" # noqa
|
||||
default_code = 'error'
|
||||
|
||||
|
||||
class FreePOSProductUniqueCheck(APIException):
|
||||
"""
|
||||
raise exception for free pos products to be unique
|
||||
"""
|
||||
|
||||
status_code = status.HTTP_403_FORBIDDEN
|
||||
default_detail = "محصول مورد نظر برای این دستگاه از قبل ثبت شده است" # noqa
|
||||
default_code = 'error'
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from rest_framework import serializers
|
||||
from apps.product import models as product_models
|
||||
from apps.pos_device.models import POSFreeProducts
|
||||
from apps.authorization.api.v1 import serializers as authorize_serializers
|
||||
from apps.authentication.api.v1.serializers.serializer import OrganizationSerializer, OrganizationTypeSerializer
|
||||
from apps.authentication.api.v1.serializers.serializer import OrganizationTypeSerializer
|
||||
from apps.product.exceptions import FreePOSProductUniqueCheck
|
||||
|
||||
|
||||
class POSFreeProductSerializer(serializers.ModelSerializer):
|
||||
@@ -10,6 +10,18 @@ class POSFreeProductSerializer(serializers.ModelSerializer):
|
||||
model = POSFreeProducts
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
"""
|
||||
@check free product for pos to be unique
|
||||
"""
|
||||
organization = attrs['organization']
|
||||
product = attrs['product']
|
||||
|
||||
if self.Meta.model.objects.filter(organization=organization, product=product).exists():
|
||||
raise FreePOSProductUniqueCheck()
|
||||
|
||||
return attrs
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user