add acceptor & terminal device to assignment - add phone to organization - set password for device when assignment

This commit is contained in:
2025-08-30 09:47:36 +03:30
parent 00edbeb847
commit 390f1afe74
4 changed files with 16 additions and 9 deletions

View File

@@ -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,

View File

@@ -5,4 +5,4 @@ from rest_framework import serializers
class DeviceSerializer(serializers.ModelSerializer):
class Meta:
model = pos_models.Device
fields = '__all__'
fields = '__all__'

View File

@@ -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(

View File

@@ -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