add acceptor & terminal device to assignment - add phone to organization - set password for device when assignment
This commit is contained in:
@@ -94,6 +94,7 @@ class OrganizationType(BaseModel):
|
||||
class Organization(BaseModel):
|
||||
name = models.CharField(max_length=250, null=True)
|
||||
en_name = models.CharField(max_length=150, null=True)
|
||||
phone = models.CharField(max_length=25, null=True)
|
||||
type = models.ForeignKey(
|
||||
'OrganizationType',
|
||||
on_delete=models.CASCADE,
|
||||
|
||||
@@ -5,4 +5,4 @@ from rest_framework import serializers
|
||||
class DeviceSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = pos_models.Device
|
||||
fields = '__all__'
|
||||
fields = '__all__'
|
||||
|
||||
@@ -66,7 +66,7 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
device.is_activated = True
|
||||
device.save()
|
||||
|
||||
if device.is_activated and device.assigned_state:
|
||||
if device.is_activated and device.assigned_state:
|
||||
# when device is logged in, its has an organization owner client, if not it will show error
|
||||
device_owner_org = self.get_device_organization()
|
||||
|
||||
@@ -74,7 +74,7 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
if not session:
|
||||
session = pos_models.Sessions.objects.create(
|
||||
device=device,
|
||||
name = headers_data['device-name'],
|
||||
name=headers_data['device-name'],
|
||||
version=headers_data['device-version'],
|
||||
mac=headers_data['device-mac'],
|
||||
ip=get_client_ip(request),
|
||||
@@ -100,23 +100,23 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
}
|
||||
|
||||
return Response({
|
||||
"message": "خوش آمدید",
|
||||
"message": "خوش آمدید", # noqa
|
||||
"device_identity": device.device_identity,
|
||||
"serial": device.serial,
|
||||
"password": device.password,
|
||||
"provider": organization.name,
|
||||
"provider_tell": '0214021',
|
||||
"provider_tell": organization.phone,
|
||||
"device_owner": org_data,
|
||||
"device_owner_users": get_users_of_organization(device_owner_org)
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
return Response({
|
||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد",
|
||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
||||
"device_identity": device.device_identity,
|
||||
"password": "****",
|
||||
"serial": device.serial,
|
||||
"provider": organization.name,
|
||||
"provider_tell": '0214021',
|
||||
"provider_tell": organization.phone,
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
else:
|
||||
@@ -129,11 +129,11 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
)
|
||||
|
||||
return Response({
|
||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد",
|
||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
||||
"device_identity": pre_device.device_identity,
|
||||
"password": "****",
|
||||
"provider": organization.name,
|
||||
"provider_tell": '0214021',
|
||||
"provider_tell": organization.phone,
|
||||
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
||||
|
||||
@action(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import random
|
||||
import string
|
||||
from datetime import timedelta
|
||||
|
||||
from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
||||
@@ -207,6 +209,10 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
||||
|
||||
# set device status to assigned
|
||||
assignment.device.assigned_state = True
|
||||
assignment.device.acceptor = request.data['device_acceptor']
|
||||
assignment.device.terminal = request.data['device_terminal']
|
||||
if not assignment.device.password:
|
||||
assignment.device.password = ''.join(random.choices(string.digits, k=6))
|
||||
assignment.device.save()
|
||||
|
||||
# set organization having pos status
|
||||
|
||||
Reference in New Issue
Block a user