device assignment bug-assignment information-bug of organizations list for assignment

This commit is contained in:
2025-08-16 14:22:00 +03:30
parent ebd3aee47f
commit 1d07501ecf
10 changed files with 120 additions and 25 deletions

View File

@@ -1,5 +1,7 @@
from rest_framework.serializers import ModelSerializer
from apps.pos_device import models as pos_models
from rest_framework.exceptions import APIException
from rest_framework import status
class POSClientSerializer(ModelSerializer):
@@ -7,6 +9,26 @@ class POSClientSerializer(ModelSerializer):
model = pos_models.POSClient
fields = '__all__'
def validate(self, attrs):
org = attrs['organization']
# check for duplicate organization client
if org:
if self.Meta.model.objects.filter(organization=org).exists():
raise APIException("قبلا کلاینت با این سازمان ثبت شده است", code=status.HTTP_403_FORBIDDEN) # noqa
return attrs
def to_representation(self, instance):
representation = super().to_representation(instance)
representation['organization'] = {
'name': instance.organization.name,
'id': instance.organization.id
}
return representation
class POSClientAttributeSerializer(ModelSerializer):
class Meta: