pos device transaction list
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-08-25 06:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('warehouse', '0013_inventoryquotasaletransaction_pos_device_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='buyer_user',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='is_active',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='sale_status',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='seller_user',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='inventoryquotasaletransaction',
|
||||||
|
name='transaction_status',
|
||||||
|
field=models.CharField(choices=[('success', 'SUCCESS'), ('waiting', 'WAITING'), ('failed', 'Failed')], max_length=25, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -74,18 +74,6 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
|||||||
related_name='inventory_sales',
|
related_name='inventory_sales',
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
buyer_user = models.ForeignKey(
|
|
||||||
User,
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name='buyer_sale_transactions',
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
seller_user = models.ForeignKey(
|
|
||||||
User,
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name='seller_sale_transactions',
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
weight = models.DecimalField(max_digits=12, decimal_places=2, null=True)
|
weight = models.DecimalField(max_digits=12, decimal_places=2, null=True)
|
||||||
delivery_address = models.TextField(blank=True, null=True)
|
delivery_address = models.TextField(blank=True, null=True)
|
||||||
product = models.ForeignKey(
|
product = models.ForeignKey(
|
||||||
@@ -98,8 +86,12 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
|||||||
description = models.TextField(blank=True, null=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
herd_owners_number = models.PositiveBigIntegerField(default=0)
|
herd_owners_number = models.PositiveBigIntegerField(default=0)
|
||||||
transactions_number = models.PositiveBigIntegerField(default=0)
|
transactions_number = models.PositiveBigIntegerField(default=0)
|
||||||
sale_status = models.BooleanField(default=False)
|
status_type = (
|
||||||
is_active = models.BooleanField(default=0)
|
('success', 'SUCCESS'),
|
||||||
|
('waiting', 'WAITING'),
|
||||||
|
('failed', 'Failed'),
|
||||||
|
)
|
||||||
|
transaction_status = models.CharField(choices=status_type, max_length=25, null=True)
|
||||||
|
|
||||||
def buyers_count(self):
|
def buyers_count(self):
|
||||||
""" number of buyers from specific inventory """
|
""" number of buyers from specific inventory """
|
||||||
|
|||||||
@@ -72,8 +72,45 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet):
|
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDeviceMixin):
|
||||||
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
|
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
|
||||||
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer
|
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer
|
||||||
filter_backends = [filters.SearchFilter]
|
search_fields = [
|
||||||
search_fields = ['']
|
"rancher__union_name",
|
||||||
|
"rancher__union_code",
|
||||||
|
"rancher__first_name",
|
||||||
|
"rancher__last_name",
|
||||||
|
"rancher__national_code",
|
||||||
|
"pos_device__device_identity",
|
||||||
|
"pos_device__serial",
|
||||||
|
"transaction_id",
|
||||||
|
"seller_organization__name",
|
||||||
|
"quota_distribution__distribution_id",
|
||||||
|
"inventory_entry__distribution__distribution_id",
|
||||||
|
"product__name",
|
||||||
|
"transaction_status",
|
||||||
|
]
|
||||||
|
date_field = "create_date"
|
||||||
|
|
||||||
|
@action(
|
||||||
|
methods=['get'],
|
||||||
|
detail=False,
|
||||||
|
url_path='transactions',
|
||||||
|
url_name='transactions',
|
||||||
|
name='transactions',
|
||||||
|
)
|
||||||
|
@transaction.atomic
|
||||||
|
def transactions(self, request):
|
||||||
|
""" pos transactions list """
|
||||||
|
|
||||||
|
# get device object
|
||||||
|
device = self.get_pos_device()
|
||||||
|
|
||||||
|
queryset = self.queryset.filter(pos_device=device)
|
||||||
|
queryset = self.filter_query(queryset)
|
||||||
|
|
||||||
|
# paginate & response
|
||||||
|
page = self.paginate_queryset(queryset)
|
||||||
|
if page is not None:
|
||||||
|
serializer = self.get_serializer(page, many=True)
|
||||||
|
return self.get_paginated_response(serializer.data)
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
|
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||||
|
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||||
from apps.warehouse.exceptions import (
|
from apps.warehouse.exceptions import (
|
||||||
InventoryEntryWeightException,
|
|
||||||
TotalInventorySaleException
|
TotalInventorySaleException
|
||||||
)
|
)
|
||||||
from apps.product.exceptions import QuotaExpiredTimeException
|
|
||||||
from apps.warehouse import models as warehouse_models
|
from apps.warehouse import models as warehouse_models
|
||||||
from apps.authorization.models import UserRelations
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta: # noqa
|
||||||
model = warehouse_models.InventoryQuotaSaleTransaction
|
model = warehouse_models.InventoryQuotaSaleTransaction
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = 0
|
depth = 0
|
||||||
@@ -74,20 +73,15 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def create(self, validated_data):
|
def to_representation(self, instance):
|
||||||
""" Custom create & set some parameters like seller & buyer """
|
""" customize output of transactions serializer """
|
||||||
|
|
||||||
distribution = validated_data['quota_distribution']
|
representation = super().to_representation(instance)
|
||||||
seller_organization = distribution.assigned_organization
|
|
||||||
|
|
||||||
user = self.context['request'].user
|
representation['rancher'] = RancherSerializer(instance.rancher).data
|
||||||
buyer_user = user
|
representation['pos_device'] = DeviceSerializer(instance.pos_device).data
|
||||||
seller_user = validated_data['inventory_entry'].created_by
|
representation['seller_organization'] = instance.seller_organization.name
|
||||||
|
representation['inventory_entry'] = InventoryEntrySerializer(instance.inventory_entry).data
|
||||||
|
|
||||||
return warehouse_models.InventoryQuotaSaleTransaction.objects.create(
|
return representation
|
||||||
seller_organization=seller_organization,
|
|
||||||
seller_user=seller_user,
|
|
||||||
buyer_user=buyer_user,
|
|
||||||
**validated_data
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user