edit assignment
This commit is contained in:
@@ -13,7 +13,7 @@ class POSClientSerializer(ModelSerializer):
|
||||
org = attrs['organization']
|
||||
|
||||
# check for duplicate organization client
|
||||
if org:
|
||||
if not self.instance and org:
|
||||
if self.Meta.model.objects.filter(organization=org).exists():
|
||||
raise APIException("قبلا کلاینت با این سازمان ثبت شده است", code=status.HTTP_403_FORBIDDEN) # noqa
|
||||
|
||||
|
||||
@@ -56,8 +56,9 @@ class DeviceAssignmentSerializer(ModelSerializer):
|
||||
device = attrs['device']
|
||||
client = attrs['client']
|
||||
|
||||
if self.Meta.model.objects.filter(device=device, client=client).exists():
|
||||
raise pos_exceptions.DeviceAlreadyAssigned()
|
||||
if not self.instance:
|
||||
if self.Meta.model.objects.filter(device=device, client=client).exists():
|
||||
raise pos_exceptions.DeviceAlreadyAssigned()
|
||||
|
||||
return attrs
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet):
|
||||
# if client will be an organization
|
||||
if request.data['client_data']['is_organization']:
|
||||
client = pos_models.POSClient.objects.filter(
|
||||
organization_id=request.data['client_data']['organization']
|
||||
organization_id=request.data['client_data']['organization']
|
||||
)
|
||||
|
||||
if client.exists():
|
||||
@@ -207,6 +207,27 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet):
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
@transaction.atomic
|
||||
def update(self, request, pk=None, *args, **kwargs):
|
||||
""" edit assignment """
|
||||
assignment = self.get_object()
|
||||
|
||||
if 'client_data' in request.data.keys():
|
||||
client = CustomOperations().custom_update(
|
||||
request=request,
|
||||
view=POSClientViewSet(),
|
||||
data_key='client_data',
|
||||
obj_id=request.data['client_data']['id']
|
||||
)
|
||||
request.data.update({'client': client['id']})
|
||||
|
||||
serializer = self.serializer_class(data=request.data, instance=assignment, partial=True)
|
||||
if serializer.is_valid():
|
||||
assignment = serializer.save()
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
|
||||
Reference in New Issue
Block a user