first setup of pos transaction - add provider, user, organization information of pos to login
This commit is contained in:
18
apps/pos_device/migrations/0063_alter_device_serial.py
Normal file
18
apps/pos_device/migrations/0063_alter_device_serial.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0 on 2025-08-26 11:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pos_device', '0062_stakeholders_default'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='device',
|
||||
name='serial',
|
||||
field=models.TextField(null=True, unique=True),
|
||||
),
|
||||
]
|
||||
@@ -34,7 +34,7 @@ class Device(BaseModel):
|
||||
device_identity = models.CharField(max_length=25, null=True)
|
||||
acceptor = models.CharField(max_length=50, null=True)
|
||||
terminal = models.CharField(max_length=50, null=True)
|
||||
serial = models.TextField(null=True)
|
||||
serial = models.TextField(null=True, unique=True)
|
||||
password = models.CharField(max_length=25, null=True)
|
||||
multi_device = models.BooleanField(default=False)
|
||||
server_in = models.BooleanField(default=False)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||
from apps.authentication.services.service import get_users_of_organization
|
||||
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
|
||||
from apps.pos_device import models as pos_models
|
||||
from rest_framework.permissions import AllowAny
|
||||
@@ -49,6 +50,7 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
serial = headers_data['device-serial']
|
||||
sdk = headers_data['device-sdk']
|
||||
psp_name = headers_data['device-provider']
|
||||
# provider organization
|
||||
organization = pos_models.Organization.objects.get(en_name=psp_name)
|
||||
|
||||
# check if device exists
|
||||
@@ -60,6 +62,8 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
# activate device
|
||||
if device:
|
||||
if (not device.is_activated or not device.pre_registered) 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()
|
||||
device.is_activated = True
|
||||
device.save()
|
||||
|
||||
@@ -78,13 +82,18 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
"message": "login success - session activated",
|
||||
"device_identity": device.device_identity,
|
||||
"serial": device.serial,
|
||||
"device_owner": organization.name
|
||||
"provider": organization.name,
|
||||
"provider_users": get_users_of_organization(organization),
|
||||
"device_owner": device_owner_org,
|
||||
"device_owner_users": get_users_of_organization(device_owner_org)
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
return Response({
|
||||
"message": "device pre registered - unauthorized",
|
||||
"device_identity": device.device_identity,
|
||||
"serial": device.serial
|
||||
"serial": device.serial,
|
||||
"provider": organization.name,
|
||||
"provider_users": get_users_of_organization(organization),
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
pre_device = pos_models.Device.objects.create(
|
||||
@@ -96,7 +105,9 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
|
||||
return Response({
|
||||
"message": "device pre-registered",
|
||||
"device_identity": pre_device.device_identity
|
||||
"device_identity": pre_device.device_identity,
|
||||
"provider": organization.name,
|
||||
"provider_users": get_users_of_organization(organization),
|
||||
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
||||
|
||||
@action(
|
||||
|
||||
Reference in New Issue
Block a user