change structure of provider companies to organizations
This commit is contained in:
@@ -41,8 +41,8 @@ class Device(BaseModel):
|
||||
latitude = models.FloatField(default=0)
|
||||
longitude = models.FloatField(default=0)
|
||||
is_activated = models.BooleanField(default=False)
|
||||
company = models.ForeignKey(
|
||||
ProviderCompany,
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='devices',
|
||||
null=True
|
||||
@@ -73,10 +73,10 @@ class DeviceActivationCode(BaseModel):
|
||||
related_name="code",
|
||||
null=True
|
||||
)
|
||||
company = models.ForeignKey(
|
||||
ProviderCompany,
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='code',
|
||||
related_name='device_activations',
|
||||
null=True
|
||||
)
|
||||
code = models.CharField(max_length=10, null=True, unique=True)
|
||||
@@ -97,10 +97,10 @@ class DeviceVersion(BaseModel):
|
||||
related_name='devices_version',
|
||||
null=True
|
||||
)
|
||||
company = models.ForeignKey(
|
||||
ProviderCompany,
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='devices_company',
|
||||
related_name='device_versions',
|
||||
null=True
|
||||
)
|
||||
name = models.CharField(max_length=250, null=True)
|
||||
@@ -210,10 +210,10 @@ class POSClientAttributeValue(BaseModel):
|
||||
|
||||
|
||||
class DeviceAssignment(BaseModel):
|
||||
company = models.ForeignKey(
|
||||
ProviderCompany,
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='assignments',
|
||||
related_name='device_assignments',
|
||||
null=True
|
||||
)
|
||||
client = models.ForeignKey(
|
||||
|
||||
@@ -4,6 +4,7 @@ from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
||||
from apps.authorization.api.v1.serializers import UserRelationSerializer
|
||||
from apps.authentication.api.v1.api import UserViewSet
|
||||
from apps.authorization.models import UserRelations
|
||||
from common.helpers import get_organization_by_user
|
||||
from rest_framework.exceptions import APIException
|
||||
from apps.pos_device import models as pos_models
|
||||
from rest_framework.response import Response
|
||||
@@ -36,7 +37,7 @@ class ProviderCompanyViewSet(viewsets.ModelViewSet): # noqa
|
||||
url_name='psp_users',
|
||||
name='psp_users'
|
||||
)
|
||||
def users_with_psp_org(self):
|
||||
def users_with_psp_org(self, request):
|
||||
""" list of psp users """
|
||||
|
||||
users = UserRelations.objects.filter(
|
||||
@@ -57,11 +58,9 @@ class DeviceViewSet(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" Custom create of pos devices """
|
||||
|
||||
if 'company' not in request.data.keys():
|
||||
company = pos_models.ProviderCompany.objects.get(
|
||||
user_relation__user=request.user
|
||||
)
|
||||
request.data.update({'company': company.id})
|
||||
if 'organization' not in request.data.keys():
|
||||
organization = get_organization_by_user(request.user)
|
||||
request.data.update({'organization': organization.id})
|
||||
|
||||
# create device
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
@@ -83,7 +82,7 @@ class DeviceViewSet(viewsets.ModelViewSet):
|
||||
""" list of company devices """
|
||||
|
||||
devices = self.queryset.filter(
|
||||
company__user_relation__user=request.user
|
||||
organization=get_organization_by_user(request.user)
|
||||
)
|
||||
|
||||
# paginate devices
|
||||
@@ -132,11 +131,9 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet):
|
||||
def device_assignment(self, request):
|
||||
""" assign pos device to client by company """
|
||||
|
||||
if 'company' not in request.data.keys():
|
||||
company = pos_models.ProviderCompany.objects.get(
|
||||
user_relation__user=request.user
|
||||
)
|
||||
request.data.update({'company': company.id})
|
||||
if 'organization' not in request.data.keys():
|
||||
organization = get_organization_by_user(request.user)
|
||||
request.data.update({'organization': organization.id})
|
||||
|
||||
# create assignment
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
@@ -144,8 +141,8 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet):
|
||||
assignment = serializer.save()
|
||||
|
||||
# set organization having pos status
|
||||
assignment.company.user_relation.organization.has_pos = True
|
||||
assignment.company.user_relation.organization.save()
|
||||
assignment.organization.has_pos = True
|
||||
assignment.organization.save()
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
Reference in New Issue
Block a user