log login error
This commit is contained in:
@@ -43,8 +43,8 @@ def organization_stats(sender, instance, **kwargs):
|
|||||||
update_organization_stats(instance.assigned_organization)
|
update_organization_stats(instance.assigned_organization)
|
||||||
else:
|
else:
|
||||||
print("assigned_organization is null")
|
print("assigned_organization is null")
|
||||||
elif sender == InventoryQuotaSaleTransaction:
|
# elif sender == InventoryQuotaSaleTransaction:
|
||||||
if instance.inventory_entry:
|
# if instance.inventory_entry:
|
||||||
update_organization_stats(instance.inventory_entry.organization)
|
# update_organization_stats(instance.inventory_entry.organization)
|
||||||
else:
|
# else:
|
||||||
print("inventory_entry is null - authentication app signals")
|
# print("inventory_entry is null - authentication app signals")
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import traceback
|
||||||
|
|
||||||
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||||
from apps.authentication.services.service import get_users_of_organization
|
from apps.authentication.services.service import get_users_of_organization
|
||||||
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
|
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
|
||||||
@@ -43,99 +45,117 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
# get device owner (organization)
|
# get device owner (organization)
|
||||||
organization = self.get_device_organization()
|
organization = self.get_device_organization()
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
# convert headers to dictionary
|
||||||
|
headers_data = {key: request.headers.get(key) for key in self.HEADERS}
|
||||||
|
|
||||||
# convert headers to dictionary
|
serial = headers_data['device-serial']
|
||||||
headers_data = {key: request.headers.get(key) for key in self.HEADERS}
|
mac = headers_data['device-mac']
|
||||||
|
psp_name = headers_data['device-provider']
|
||||||
|
|
||||||
serial = headers_data['device-serial']
|
# provider organization
|
||||||
mac = headers_data['device-mac']
|
organization = pos_models.Organization.objects.get(en_name=psp_name)
|
||||||
psp_name = headers_data['device-provider']
|
|
||||||
|
|
||||||
# provider organization
|
device = self.device_queryset.filter(serial=serial).first()
|
||||||
organization = pos_models.Organization.objects.get(en_name=psp_name)
|
|
||||||
|
|
||||||
device = self.device_queryset.filter(serial=serial).first()
|
if not device and 'device_identity' in request.data.keys() and request.data['device_identity'] != "":
|
||||||
|
device = self.device_queryset.filter(device_identity=request.data['device_identity']).first()
|
||||||
if not device and 'device_identity' in request.data.keys() and request.data['device_identity'] != "":
|
|
||||||
device = self.device_queryset.filter(device_identity=request.data['device_identity']).first()
|
|
||||||
|
|
||||||
if device:
|
|
||||||
if not device.is_activated and device.pre_registered and device.assigned_state:
|
|
||||||
# activate device
|
|
||||||
device.is_activated = True
|
|
||||||
device.save()
|
|
||||||
|
|
||||||
if device.is_activated and device.assigned_state:
|
if device:
|
||||||
# when device is logged in, its has an organization owner client, if not it will show error
|
if not device.is_activated and device.pre_registered and device.assigned_state:
|
||||||
device_owner_org = self.get_device_organization()
|
# activate device
|
||||||
|
device.is_activated = True
|
||||||
|
device.save()
|
||||||
|
|
||||||
session = self.session_queryset.filter(serial=serial).first()
|
if device.is_activated and device.assigned_state:
|
||||||
if not session:
|
# when device is logged in, its has an organization owner client, if not it will show error
|
||||||
pos_models.Sessions.objects.create(
|
device_owner_org = self.get_device_organization()
|
||||||
device=device,
|
|
||||||
name=headers_data['device-name'],
|
|
||||||
version=headers_data['device-version'],
|
|
||||||
mac=headers_data['device-mac'],
|
|
||||||
ip=get_client_ip(request),
|
|
||||||
sdk=headers_data['device-sdk'],
|
|
||||||
serial=headers_data['device-serial'],
|
|
||||||
latitude=headers_data['device-lot'],
|
|
||||||
longitude=headers_data['device-lng'],
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
session.name = headers_data['device-name']
|
|
||||||
session.version = headers_data['device-version']
|
|
||||||
session.mac = headers_data['device-mac']
|
|
||||||
session.ip = get_client_ip(request)
|
|
||||||
session.sdk = headers_data['device-sdk']
|
|
||||||
session.latitude = headers_data['device-lot']
|
|
||||||
session.longitude = headers_data['device-lng']
|
|
||||||
session.save()
|
|
||||||
|
|
||||||
org_data = {
|
session = self.session_queryset.filter(serial=serial).first()
|
||||||
'id': device_owner_org.id,
|
if not session:
|
||||||
'name': device_owner_org.name,
|
pos_models.Sessions.objects.create(
|
||||||
'en_name': device_owner_org.en_name
|
device=device,
|
||||||
}
|
name=headers_data['device-name'],
|
||||||
|
version=headers_data['device-version'],
|
||||||
|
mac=headers_data['device-mac'],
|
||||||
|
ip=get_client_ip(request),
|
||||||
|
sdk=headers_data['device-sdk'],
|
||||||
|
serial=headers_data['device-serial'],
|
||||||
|
latitude=headers_data['device-lot'],
|
||||||
|
longitude=headers_data['device-lng'],
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
session.name = headers_data['device-name']
|
||||||
|
session.version = headers_data['device-version']
|
||||||
|
session.mac = headers_data['device-mac']
|
||||||
|
session.ip = get_client_ip(request)
|
||||||
|
session.sdk = headers_data['device-sdk']
|
||||||
|
session.latitude = headers_data['device-lot']
|
||||||
|
session.longitude = headers_data['device-lng']
|
||||||
|
session.save()
|
||||||
|
|
||||||
|
org_data = {
|
||||||
|
'id': device_owner_org.id,
|
||||||
|
'name': device_owner_org.name,
|
||||||
|
'en_name': device_owner_org.en_name
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response({
|
||||||
|
"message": "خوش آمدید", # noqa
|
||||||
|
"device_identity": device.device_identity,
|
||||||
|
"serial": device.serial,
|
||||||
|
"password": device.password,
|
||||||
|
"provider": organization.name,
|
||||||
|
"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({
|
return Response({
|
||||||
"message": "خوش آمدید", # noqa
|
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
||||||
"device_identity": device.device_identity,
|
"device_identity": device.device_identity,
|
||||||
|
"password": "****",
|
||||||
"serial": device.serial,
|
"serial": device.serial,
|
||||||
"password": device.password,
|
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_tell": organization.phone,
|
"provider_tell": organization.phone,
|
||||||
"device_owner": org_data,
|
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||||
"device_owner_users": get_users_of_organization(device_owner_org)
|
|
||||||
}, status=status.HTTP_200_OK)
|
else:
|
||||||
|
pre_device = pos_models.Device.objects.create(
|
||||||
return Response({
|
serial=serial,
|
||||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
mac=mac,
|
||||||
"device_identity": device.device_identity,
|
organization=organization,
|
||||||
"password": "****",
|
pre_registered=True,
|
||||||
"serial": device.serial,
|
is_activated=False
|
||||||
"provider": organization.name,
|
)
|
||||||
"provider_tell": organization.phone,
|
|
||||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
return Response({
|
||||||
|
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
||||||
else:
|
"device_identity": pre_device.device_identity,
|
||||||
pre_device = pos_models.Device.objects.create(
|
"password": "****",
|
||||||
serial=serial,
|
"provider": organization.name,
|
||||||
mac=mac,
|
"provider_tell": organization.phone,
|
||||||
organization=organization,
|
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
||||||
pre_registered=True,
|
except Exception as e:
|
||||||
is_activated=False
|
error_message = str(e)
|
||||||
|
error_title = e.__class__.__name__
|
||||||
|
error_traceback = traceback.format_exc()
|
||||||
|
print(error_message)
|
||||||
|
print(error_title)
|
||||||
|
print(error_traceback)
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
{
|
||||||
|
"result": "خطای سرور داخلی رخ داده است. لطفا بعدا تلاش کنید.",
|
||||||
|
"error_message": error_message,
|
||||||
|
"error_title": error_title,
|
||||||
|
"error_traceback": error_traceback,
|
||||||
|
},
|
||||||
|
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response({
|
|
||||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
|
||||||
"device_identity": pre_device.device_identity,
|
|
||||||
"password": "****",
|
|
||||||
"provider": organization.name,
|
|
||||||
"provider_tell": organization.phone,
|
|
||||||
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['post'],
|
methods=['post'],
|
||||||
detail=False,
|
detail=False,
|
||||||
url_path='merge_devices',
|
url_path='merge_devices',
|
||||||
|
|||||||
@@ -243,9 +243,9 @@ def update_stats_on_change(sender, instance, **kwargs):
|
|||||||
if sender == QuotaDistribution:
|
if sender == QuotaDistribution:
|
||||||
update_product_stats(instance.quota.product, instance)
|
update_product_stats(instance.quota.product, instance)
|
||||||
update_quota_stats(instance.quota)
|
update_quota_stats(instance.quota)
|
||||||
elif sender == InventoryQuotaSaleTransaction:
|
# elif sender == InventoryQuotaSaleTransaction:
|
||||||
if instance.quota_distribution:
|
# if instance.quota_distribution:
|
||||||
update_product_stats(instance.quota_distribution.quota.product, instance.quota_distribution)
|
# update_product_stats(instance.quota_distribution.quota.product, instance.quota_distribution)
|
||||||
update_quota_stats(instance.quota_distribution.quota)
|
# update_quota_stats(instance.quota_distribution.quota)
|
||||||
else:
|
# else:
|
||||||
print("quota distribution is null - product app signal")
|
# print("quota distribution is null - product app signal")
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-09-14 06:02
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('warehouse', '0021_inventoryquotasaletransaction_weight'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='inventory_entry',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='quota_distribution',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-09-14 07:13
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0072_alter_quota_base_price_cooperative_and_more'),
|
||||||
|
('warehouse', '0022_remove_inventoryquotasaletransaction_inventory_entry_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='inventory_entry',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='inventory_sales', to='warehouse.inventoryentry'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='quota_distribution',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='inventory_sales', to='product.quotadistribution'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -72,7 +72,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
|||||||
]
|
]
|
||||||
|
|
||||||
# paginate & response
|
# paginate & response
|
||||||
page = self.paginate_queryset(available_entries)
|
page = self.paginate_queryset(available_entries) # noqa
|
||||||
if page is not None:
|
if page is not None:
|
||||||
serializer = self.get_serializer(page, many=True, context={'rancher': rancher.first(), 'device': device})
|
serializer = self.get_serializer(page, many=True, context={'rancher': rancher.first(), 'device': device})
|
||||||
# set custom message for paginator
|
# set custom message for paginator
|
||||||
|
|||||||
@@ -165,8 +165,6 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
representation['pos_device'] = DeviceSerializer(instance.pos_device).data
|
representation['pos_device'] = DeviceSerializer(instance.pos_device).data
|
||||||
if instance.seller_organization:
|
if instance.seller_organization:
|
||||||
representation['seller_organization'] = instance.seller_organization.name
|
representation['seller_organization'] = instance.seller_organization.name
|
||||||
if instance.inventory_entry:
|
|
||||||
representation['inventory_entry'] = InventoryEntrySerializer(instance.inventory_entry).data
|
|
||||||
|
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ def update_distribution_warehouse_entry(sender, instance, **kwargs):
|
|||||||
warehouse_sold_and_balance(instance.distribution)
|
warehouse_sold_and_balance(instance.distribution)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=InventoryQuotaSaleTransaction)
|
# @receiver(post_save, sender=InventoryQuotaSaleTransaction)
|
||||||
@receiver(post_delete, sender=InventoryQuotaSaleTransaction)
|
# @receiver(post_delete, sender=InventoryQuotaSaleTransaction)
|
||||||
def update_distribution_warehouse_sold_and_balance(sender, instance, **kwargs):
|
# def update_distribution_warehouse_sold_and_balance(sender, instance, **kwargs):
|
||||||
if instance.quota_distribution:
|
# if instance.quota_distribution:
|
||||||
warehouse_sold_and_balance(instance.quota_distribution)
|
# warehouse_sold_and_balance(instance.quota_distribution)
|
||||||
else:
|
# else:
|
||||||
print("quota distribution is null - warehouse app signals")
|
# print("quota distribution is null - warehouse app signals")
|
||||||
|
|||||||
Reference in New Issue
Block a user