From afbb3fbd1a66fd5bd92b345ba289fa724d25a799 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 25 Oct 2025 10:40:24 +0330 Subject: [PATCH] add device-identity to stakeholder serializer --- .../web/api/v1/serilaizers/device.py | 2 ++ apps/pos_device/web/api/v1/viewsets/device.py | 23 +------------------ 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/apps/pos_device/web/api/v1/serilaizers/device.py b/apps/pos_device/web/api/v1/serilaizers/device.py index 1fa3a25..6af0be1 100644 --- a/apps/pos_device/web/api/v1/serilaizers/device.py +++ b/apps/pos_device/web/api/v1/serilaizers/device.py @@ -85,6 +85,8 @@ class StakeHoldersSerializer(ModelSerializer): instance.organization.bank_information.all().first() ).data + representation['device'] = instance.device.device_identity + representation['organization'] = { 'name': instance.organization.name, 'id': instance.organization.id diff --git a/apps/pos_device/web/api/v1/viewsets/device.py b/apps/pos_device/web/api/v1/viewsets/device.py index 9bcacfa..ac1ded2 100644 --- a/apps/pos_device/web/api/v1/viewsets/device.py +++ b/apps/pos_device/web/api/v1/viewsets/device.py @@ -259,36 +259,15 @@ class DeviceAssignmentViewSet(SoftDeleteMixin, viewsets.ModelViewSet): def update(self, request, pk=None, *args, **kwargs): """ edit assignment """ assignment = self.get_object() - assignment.delete() + # delete assignment & recreate it as new re_create_assignment = self.create(request, *args, **kwargs) - print(re_create_assignment.data) assignment = self.queryset.get(id=re_create_assignment.data['id']) assignment.organization = pos_models.Organization.objects.get( id=re_create_assignment.data['client']['organization']['id'] ) assignment.save() - # 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() - # - # if assignment.client.organization: - # # update default stake holder for device (assignment) - # stake_holder = assignment.stake_holders.filter(default=True).first() - # stake_holder.organization = assignment.client.organization - # stake_holder.save() - # - # return Response(serializer.data, status=status.HTTP_200_OK) return re_create_assignment @action(