From cb0b12698dc6a2f19ce80b72e8014b7b436b4396 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 26 Jul 2025 08:18:09 +0330 Subject: [PATCH] add pk in quota activate --- apps/pos_device/models.py | 13 +++++++++++++ apps/product/web/api/v1/viewsets/quota_api.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/pos_device/models.py b/apps/pos_device/models.py index 8009586..94d3adf 100644 --- a/apps/pos_device/models.py +++ b/apps/pos_device/models.py @@ -1,3 +1,6 @@ +import random +import string + from apps.authentication.models import Organization from django.contrib.postgres.fields import ArrayField from apps.authorization.models import UserRelations @@ -24,6 +27,7 @@ class ProviderCompany(BaseModel): class Device(BaseModel): + device_identity = models.CharField(max_length=25, null=True) acceptor = models.IntegerField(default=0) terminal = models.IntegerField(default=0) serial = models.TextField(null=True) @@ -45,6 +49,15 @@ class Device(BaseModel): def save(self, *args, **kwargs): return super(Device, self).save(*args, **kwargs) + def generate_device_identity(self): + """ generate identity for every device """ + prefix = "POS" + while True: + number_part = ''.join(random.choices(string.digits, k=6)) + code = f"{prefix}{number_part}" + if not self.objects.filter(short_code=code).exists(): + return code + class DeviceVersion(BaseModel): device = models.ForeignKey( diff --git a/apps/product/web/api/v1/viewsets/quota_api.py b/apps/product/web/api/v1/viewsets/quota_api.py index c35b52f..d78586f 100644 --- a/apps/product/web/api/v1/viewsets/quota_api.py +++ b/apps/product/web/api/v1/viewsets/quota_api.py @@ -275,7 +275,7 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa url_name='activate', name='activate' ) - def activate(self, request): + def activate(self, request, pk=None): """ to activate quota """ quota = self.get_object()