fix - mydevices
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user