pos client & quota limit organization blank

This commit is contained in:
2025-07-22 08:16:40 +03:30
parent d1742b5d72
commit 241e373d15
15 changed files with 271 additions and 6 deletions

View File

@@ -0,0 +1,66 @@
# Generated by Django 5.0 on 2025-07-22 04:45
import django.contrib.postgres.fields
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pos_device', '0004_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddField(
model_name='posclientattribute',
name='choices',
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=150), null=True, size=None),
),
migrations.AddField(
model_name='posclientattribute',
name='client_type',
field=models.CharField(choices=[('business', 'صنف'), ('person', 'شخص آزاد'), ('organization', 'سازمان')], max_length=25, null=True),
),
migrations.AddField(
model_name='posclientattribute',
name='field_type',
field=models.CharField(choices=[('text', 'متن'), ('number', 'عدد'), ('date', 'تاریخ'), ('choice', 'چند کزینه ای')], max_length=20, null=True),
),
migrations.AddField(
model_name='posclientattribute',
name='key',
field=models.CharField(max_length=100, null=True),
),
migrations.AddField(
model_name='posclientattribute',
name='label',
field=models.CharField(max_length=255, null=True),
),
migrations.AddField(
model_name='posclientattribute',
name='required',
field=models.BooleanField(default=False),
),
migrations.CreateModel(
name='POSClientAttributeValue',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_date', models.DateTimeField(auto_now_add=True)),
('modify_date', models.DateTimeField(auto_now=True)),
('creator_info', models.CharField(max_length=100, null=True)),
('modifier_info', models.CharField(max_length=100, null=True)),
('trash', models.BooleanField(default=False)),
('value', models.TextField(null=True)),
('attribute', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='attribute_values', to='pos_device.posclientattribute')),
('client', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='attribute_values', to='pos_device.posclient')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_createddby', to=settings.AUTH_USER_MODEL)),
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modifiedby', to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]

View File

@@ -1,6 +1,7 @@
from django.db import models
from apps.core.models import BaseModel
from apps.authentication.models import Organization
from django.contrib.postgres.fields import ArrayField
class ProviderCompany(BaseModel):
@@ -111,4 +112,46 @@ class POSClient(BaseModel):
class POSClientAttribute(BaseModel):
pass
client_type = models.CharField(max_length=25, choices=[
('business', 'صنف'),
('person', 'شخص آزاد'), # noqa
('organization', 'سازمان') # noqa
], null=True)
key = models.CharField(max_length=100, null=True)
label = models.CharField(max_length=255, null=True)
field_type = models.CharField(max_length=20, choices=[
('text', 'متن'),
('number', 'عدد'),
('date', 'تاریخ'), # noqa
('choice', 'چند کزینه ای'), # noqa
], null=True)
required = models.BooleanField(default=False)
choices = ArrayField(base_field=models.CharField(max_length=150), null=True)
def __str__(self):
return f'attribute: {self.key}-{self.field_type}'
def save(self, *args, **kwargs):
return super(POSClientAttribute, self).save(*args, **kwargs)
class POSClientAttributeValue(BaseModel):
client = models.ForeignKey(
POSClient,
on_delete=models.CASCADE,
related_name='attribute_values',
null=True
)
attribute = models.ForeignKey(
POSClientAttribute,
on_delete=models.CASCADE,
related_name='attribute_values',
null=True
)
value = models.TextField(null=True)
def __str__(self):
return f'Client Attribute: {self.client.name}-{self.attribute.key}'
def save(self, *args, **kwargs):
return super(POSClientAttributeValue, self).save(*args, **kwargs)

View File

@@ -1,5 +1,5 @@
from django.urls import path, include
urlpatterns = [
path('', include(''))
path('web/', include('apps.pos_device.web.api.v1.urls'))
]

View File

@@ -0,0 +1,46 @@
from rest_framework.serializers import ModelSerializer
from apps.pos_device import models as pos_models
class ProviderCompanySerializer(ModelSerializer):
class Meta:
model = pos_models.ProviderCompany
fields = '__all__'
class DeviceSerializer(ModelSerializer):
class Meta:
model = pos_models.Device
fields = '__all__'
class DeviceVersionSerializer(ModelSerializer):
class Meta:
model = pos_models.DeviceVersion
fields = '__all__'
class SessionSerializer(ModelSerializer):
class Meta:
model = pos_models.Sessions
fields = '__all__'
class POSClientSerializer(ModelSerializer):
class Meta:
model = pos_models.POSClient
fields = '__all__'
class POSClientAttributeSerializer(ModelSerializer):
class Meta:
model = pos_models.POSClientAttribute
fields = '__all__'
class POSClientAttributeValueSerializer(ModelSerializer):
class Meta:
model = pos_models.POSClientAttributeValue
fields = '__all__'

View File

@@ -0,0 +1,8 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
urlpatterns = [
path('v1/pos/', include(router.urls))
]

View File

@@ -0,0 +1,40 @@
from apps.pos_device.web.api.v1.serilaizers import serializers as pos_serializer
from apps.pos_device import models as pos_models
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework import status
class ProviderCompanyViewSet(viewsets.ModelViewSet): # noqa
queryset = pos_models.ProviderCompany.objects.all()
serializer_class = pos_serializer.ProviderCompanySerializer
class DeviceViewSet(viewsets.ModelViewSet):
queryset = pos_models.Device.objects.all()
serializer_class = pos_serializer.DeviceSerializer
class DeviceVersionViewSet(viewsets.ModelViewSet):
queryset = pos_models.DeviceVersion.objects.all()
serializer_class = pos_serializer.DeviceVersionSerializer
class SessionViewSet(viewsets.ModelViewSet): # noqa
queryset = pos_models.Sessions.objects.all()
serializer_class = pos_serializer.SessionSerializer
class POSClientViewSet(viewsets.ModelViewSet):
queryset = pos_models.POSClient.objects.all()
serializer_class = pos_serializer.POSClientSerializer
class POSClientAttributeViewSet(viewsets.ModelViewSet):
queryset = pos_models.POSClientAttribute.objects.all()
serializer_class = pos_serializer.POSClientAttributeSerializer
class POSClientAttributeValueViewSet(viewsets.ModelViewSet):
queryset = pos_models.POSClientAttributeValue.objects.all()
serializer_class = pos_serializer.POSClientAttributeValueSerializer