add pk in quota activate
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
from apps.authentication.models import Organization
|
from apps.authentication.models import Organization
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
from apps.authorization.models import UserRelations
|
from apps.authorization.models import UserRelations
|
||||||
@@ -24,6 +27,7 @@ class ProviderCompany(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class Device(BaseModel):
|
class Device(BaseModel):
|
||||||
|
device_identity = models.CharField(max_length=25, null=True)
|
||||||
acceptor = models.IntegerField(default=0)
|
acceptor = models.IntegerField(default=0)
|
||||||
terminal = models.IntegerField(default=0)
|
terminal = models.IntegerField(default=0)
|
||||||
serial = models.TextField(null=True)
|
serial = models.TextField(null=True)
|
||||||
@@ -45,6 +49,15 @@ class Device(BaseModel):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
return super(Device, self).save(*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):
|
class DeviceVersion(BaseModel):
|
||||||
device = models.ForeignKey(
|
device = models.ForeignKey(
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
url_name='activate',
|
url_name='activate',
|
||||||
name='activate'
|
name='activate'
|
||||||
)
|
)
|
||||||
def activate(self, request):
|
def activate(self, request, pk=None):
|
||||||
""" to activate quota """
|
""" to activate quota """
|
||||||
|
|
||||||
quota = self.get_object()
|
quota = self.get_object()
|
||||||
|
|||||||
Reference in New Issue
Block a user