fix - device pre register & exception handling with json response

This commit is contained in:
2025-11-09 14:35:14 +03:30
parent 0c5142aff3
commit c0f289284f
7 changed files with 118 additions and 9 deletions

View File

@@ -0,0 +1,33 @@
# Generated by Django 5.0 on 2025-11-09 11:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('authentication', '0048_alter_bankaccountinformation_account_and_more'),
]
operations = [
migrations.AlterField(
model_name='bankaccountinformation',
name='account',
field=models.CharField(blank=True, max_length=25, null=True),
),
migrations.AlterField(
model_name='bankaccountinformation',
name='card',
field=models.CharField(blank=True, max_length=25, null=True),
),
migrations.AlterField(
model_name='bankaccountinformation',
name='name',
field=models.CharField(blank=True, max_length=150, null=True),
),
migrations.AlterField(
model_name='bankaccountinformation',
name='sheba',
field=models.CharField(blank=True, max_length=30, null=True),
),
]

View File

@@ -78,6 +78,10 @@ class DeviceViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, AdminFi
organization = get_organization_by_user(request.user)
request.data.update({'organization': organization.id})
# ser device preregister to true
# if device create in web panel, set to true for recognize by pos device
request.data.update({'pre_registered': True})
# create device
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():

View File

@@ -0,0 +1,28 @@
from django.db.models import Sum
from apps.product import models as product_models
class QuotaDistributionService:
"""
Service layer to manage multiple quota distributions as one unified entity.
Used for organization-based views and POS operations.
"""
def __init__(self, quota, organization):
self.quota = quota
self.organization = organization
self.distribution = product_models.QuotaDistribution.objects.filter(
quota=quota,
assigned_organization=organization,
quota__is_closed=False,
warehouse_entry__gt=0
).first()
@property
def total_weight(self):
return self.distribution.aggregate(
total=Sum('weight')
)['total'] or 0
pass

View File

@@ -0,0 +1,43 @@
# Generated by Django 5.0 on 2025-11-09 11:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('warehouse', '0040_inventoryquotasaleitem_base_price_and_more'),
]
operations = [
migrations.AlterField(
model_name='inventoryquotasaletransaction',
name='payer_cart',
field=models.CharField(blank=True, max_length=50, null=True),
),
migrations.AlterField(
model_name='inventoryquotasaletransaction',
name='rancher_fullname',
field=models.CharField(blank=True, max_length=150, null=True),
),
migrations.AlterField(
model_name='inventoryquotasaletransaction',
name='rancher_mobile',
field=models.CharField(blank=True, max_length=25, null=True),
),
migrations.AlterField(
model_name='inventoryquotasaletransaction',
name='ref_num',
field=models.CharField(blank=True, max_length=50, null=True),
),
migrations.AlterField(
model_name='inventoryquotasaletransaction',
name='result_text',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='inventoryquotasaletransaction',
name='terminal',
field=models.CharField(blank=True, max_length=50, null=True),
),
]

View File

@@ -66,8 +66,8 @@ class InventoryQuotaSaleTransaction(BaseModel):
related_name='transactions',
null=True
)
rancher_fullname = models.CharField(max_length=150, null=True)
rancher_mobile = models.CharField(max_length=25, null=True)
rancher_fullname = models.CharField(max_length=150, null=True, blank=True)
rancher_mobile = models.CharField(max_length=25, null=True, blank=True)
pos_device = models.ForeignKey(
Device,
on_delete=models.CASCADE,
@@ -119,10 +119,10 @@ class InventoryQuotaSaleTransaction(BaseModel):
)
transaction_status = models.CharField(choices=status_type, max_length=25, null=True)
transaction_status_code = models.IntegerField(default=0)
result_text = models.TextField(null=True)
ref_num = models.CharField(max_length=50, null=True)
terminal = models.CharField(max_length=50, null=True)
payer_cart = models.CharField(max_length=50, null=True)
result_text = models.TextField(null=True, blank=True)
ref_num = models.CharField(max_length=50, null=True, blank=True)
terminal = models.CharField(max_length=50, null=True, blank=True)
payer_cart = models.CharField(max_length=50, null=True, blank=True)
pos_date = models.PositiveBigIntegerField(default=0)
transaction_date = models.DateTimeField(auto_now_add=True, null=True)
free_sale_state = models.BooleanField(default=False)