From 9d7c0658195cf47205b624571dc6197e170a8ce5 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 11 Nov 2025 12:36:04 +0330 Subject: [PATCH] fix - mydevices --- .env.local | 2 +- apps/core/visibility_registry.py | 7 +++--- apps/pos_device/web/api/v1/viewsets/device.py | 22 +++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.env.local b/.env.local index 63983c1..4ff1bc4 100644 --- a/.env.local +++ b/.env.local @@ -7,7 +7,7 @@ ENV_NAME=DEV # Database secrets DB_HOST=31.7.78.133 DB_PORT=14352 -DB_NAME=Production +DB_NAME=Development DB_USERNAME=postgres DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV diff --git a/apps/core/visibility_registry.py b/apps/core/visibility_registry.py index 2119e8f..6bb4e0e 100644 --- a/apps/core/visibility_registry.py +++ b/apps/core/visibility_registry.py @@ -7,7 +7,7 @@ VISIBILITY_MAP = { 'quotadistribution': ['assigner_organization', 'assigned_organization'], 'inventoryentry': 'organization', 'inventoryquotasaletransaction': 'seller_organization', - 'device': 'organization', + 'device': 'assignment__client__organization', # 'deviceactivationcode': 'organization', # 'deviceversion': 'organization', @@ -21,9 +21,10 @@ VISIBILITY_MAP = { VISIBILITY_MAP_BY_ORG_KEY = { 'device': { 'PSP': 'organization', - # 'CO': 'assignment__client__organization', + 'CO': 'assignment__client__organization', 'CI': 'assignment__client__organization', - 'PR': 'assignment__client__organization', + 'U': 'assignment__client__organization', 'AGC': 'assignment__client__organization', + 'EMP': 'assignment__client__organization', }, } diff --git a/apps/pos_device/web/api/v1/viewsets/device.py b/apps/pos_device/web/api/v1/viewsets/device.py index 0fd8aee..4d53dc1 100644 --- a/apps/pos_device/web/api/v1/viewsets/device.py +++ b/apps/pos_device/web/api/v1/viewsets/device.py @@ -4,7 +4,7 @@ from datetime import timedelta from django.db import transaction from django.utils.timezone import now -from rest_framework import status +from rest_framework import status, filters from rest_framework import viewsets from rest_framework.decorators import action from rest_framework.exceptions import APIException @@ -70,6 +70,15 @@ class ProviderCompanyViewSet(SoftDeleteMixin, viewsets.ModelViewSet): # noqa class DeviceViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, AdminFilterMixin): queryset = pos_models.Device.objects.all() serializer_class = device_serializer.DeviceSerializer + filter_backends = [filters.SearchFilter] + search_fields = [ + 'device_identity', + 'acceptor', + 'terminal', + 'mac', + 'serial', + 'organization__name', + ] def create(self, request, *args, **kwargs): """ Custom create of pos devices """ @@ -105,7 +114,16 @@ class DeviceViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, AdminFi visibility_by_org_scope=True ) if organization.free_visibility_by_scope else self.get_queryset() - queryset = apply_visibility_filter_by_org_type(devices, organization) + # filter by Jihad & admin of system + if organization.type.key == 'J': + queryset = devices.filter(assignment__client__organization__province=organization.province) + elif not organization.type.key == 'ADM': + queryset = apply_visibility_filter_by_org_type(devices, organization) + else: + queryset = devices + + # filter by search + queryset = self.filter_queryset(queryset) # paginate devices page = self.paginate_queryset(queryset)