device assignment bug-assignment information-bug of organizations list for assignment
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from apps.pos_device.web.api.v1.serilaizers import client as client_serializer
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from apps.pos_device import models as pos_models
|
||||
from rest_framework.exceptions import APIException
|
||||
from apps.pos_device import exceptions as pos_exceptions
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
class ProviderCompanySerializer(ModelSerializer):
|
||||
@@ -23,6 +27,10 @@ class DeviceSerializer(ModelSerializer):
|
||||
'province': instance.organization.province.id
|
||||
}
|
||||
|
||||
representation['assignment'] = DeviceAssignmentSerializer(
|
||||
instance.assignment.all().first()
|
||||
).data
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
@@ -43,6 +51,23 @@ class DeviceAssignmentSerializer(ModelSerializer):
|
||||
model = pos_models.DeviceAssignment
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
|
||||
device = attrs['device']
|
||||
client = attrs['client']
|
||||
|
||||
if self.Meta.model.objects.filter(device=device, client=client).exists():
|
||||
raise pos_exceptions.DeviceAlreadyAssigned()
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
representation['client'] = client_serializer.POSClientSerializer(
|
||||
instance.client
|
||||
).data
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
class StakeHoldersSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user